猿问

MySQL-根据用户的选择选择列“名称”,其中列“ id”和“父”中的行彼此相等

当父代= 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.这是对category字段的查询,它很好用,并为我们提供了用户的选择($ 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();


假设1-包含='。$ db-> quote($ judgePick)的id


假设2-对于父级> 0,必须等于假设1中用户选择的ID


预期结果


子类别字段仅在用户选择ID等于父项的类别字段($ judgePick)中根据用户的选择具有名称。换句话说,例如,艺术与娱乐是类别(parent = 0)并具有(id = 1),并且当用户在类别表单字段中选择它时,子类别表单字段应显示所有带有(parent = 1)的名称


弑天下
浏览 127回答 2
2回答

Cats萌萌

那这个呢$db->setQuery("SELECT name FROM #__professional_categ WHERE parent=$judgePick AND active=1 ORDER BY name ASC");
随时随地看视频慕课网APP
我要回答