When parent = 0 means category
When parent = 1 means subcategory 1 connected to category 1 (id=1)
When parent = 2 means subcategory 2 connected to category 2 (id=2)
When parent... etc until 19 categories (id=19 with parent=0)
What I need is to bring the names of subcategories in the sub-category form field according to user's choice in the category field. The category field works fine.
id parent name active
1 0 Arts & Entertainment 0
2 0 Automotive 0
3 0 Business & Professional Serv. 1
4 0 Clothing & Accessories 0
5 0 Community & Government 0
6 0 Computers & Electronics 1
7 0 Construction & Contractors 0
8 0 Education 0
9 0 Food & Dining 0
10 0 Health & Medicine 0
11 0 Home & Garden 0
12 0 Industry & Agriculture 0
13 0 Legal & Financial 1
14 0 Media & Communications 0
15 0 Personal Care & Services 0
16 0 Real Estate 0
17 0 Shopping 0
18 0 Sports & Recreation 0
19 0 Travel & Transportation 0
34 1 Acting Schools 1
35 1 Aerial Photographers 1
36 1 Arcades & Amusements 1
37 1 Art Classes 1
38 1 Art Galleries & Dealers 1
39 1 Art Schools 1
1.This is the Query for the category field which works fine and gives us the user's choice ($judgePick)
$db->setQuery('SELECT name FROM #__professional_categ WHERE parent=0 AND active=1 ORDER BY name ASC');
2.This is the Query for the subcategory field trying to solve
$judgePick = JRequest::getVar('category');
$db = JFactory::getDBO();
$db->setQuery('SELECT `name` FROM `#__professional_categ` WHERE active = 1 AND (something here...) ORDER BY parent ASC, name ASC);
$result = $db->loadColumn();
if(!$result){
echo "error";
} else {
echo json_encode($result);
}
Assumption 1 - id to include ='.$db->quote($judgePick)
Assumption 2 - For parent > 0 has to be equal to id of user's choice in Assumption 1
Expected result
Subcategory field to have the names ONLY according to user's choice in category field ($judgePick) where user's choice id equals parent. In other words, e.g. Arts & Entertainment is the category (parent=0) and has (id =1) and when the user chooses it in category form field, the subcategory form field should show all names with (parent=1)