Some weeks ago I posted this and I realized from the referrals that it may help to be as a code snippet. This is an example of getting products details from categories – subcategories using ajax call. I am fond of OOP and this is not , but I believe that will help others understand of how this things can happen.
Demand: There are some sound systems of cars (products) each of them has an article link and some other details (e.g. Voltage) ,those products can be categorized , so we have categories of them. The categories can have either subcategories or are a category that has products. We want to display all the categories that have products in a select, and when a user selects one of them to see all the products of it with an AJAX call.
We have two tables, categories and products, here are the create table of them
CREATE TABLE `categories` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`PARENT_ID` int(10) NOT NULL,
`TYPE` smallint(1) NOT NULL COMMENT '0 Category with subcategories | 1 Category with products',
`TITLE` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`STATUS` smallint(1) NOT NULL DEFAULT '1' COMMENT '0 Inactive | 1 Active',
PRIMARY KEY (`ID`)
) ENGINE=MyISAM
When a gategory has parent id 0 than it is a top category
CREATE TABLE `products` (
`ID` int(10) NOT NULL AUTO_INCREMENT,
`CATEGORY_ID` int(10) NOT NULL,
`ARTICLE_LINK` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`PRODUCT_LINE` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`VOLTAGE` int(4) NOT NULL,
`BATTERY` int(4) NOT NULL,
`ELECTRIC_POWER` int(4) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM
An OOP MVC implementation of that is here http://phpwebframework.com/an-elementary-example-with-categories-subcategories-products-and-ajax using PWF