当 parent = 0 表示类别
当 parent = 1 表示子类别 1 连接到类别 1 (id=1)
当 parent = 2 表示子类别 2 连接到类别 2 (id=2)
当父母...等直到19个类别(id=19,父母=0)
我需要的是根据用户在类别字段中的选择将子类别的名称带到子类别表单字段中。类别字段工作正常。
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.这是对类别字段的查询,它工作正常并为我们提供了用户的选择($judgePick)
$db->setQuery('SELECT name FROM #__professional_categ WHERE parent=0 AND active=1 ORDER BY name ASC');
2.这是试图解决的子类别字段的查询
$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);
}
假设 1 - id 包括 ='.$db->quote($judgePick)
假设 2 - 对于 parent > 0 必须等于假设 1 中用户选择的 id
预期结果
子类别字段的名称仅根据用户在类别字段 ($judgePick) 中的选择,其中用户的选择 id 等于父项。换句话说,例如 Arts & Entertainment 是类别 (parent=0) 并且具有 (id =1),当用户在类别表单字段中选择它时,子类别表单字段应显示所有具有 (parent=1) 的名称