且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

类别下拉过滤器应该只包含实际有数据的类别?如何生成动态下拉列表?

更新时间:2023-11-30 15:14:04

Torakami写道:
Torakami wrote:

但现在我想要做的是我只想在下拉列表中显示那些类别肯定会给我数据

But now what i want to do is i want to display only those categories in dropdowns which are surely give me the data

这不是什么大不了的事。只需加载与详细信息表数据匹配的数据。

例如,您有两个表Country& City。

It's not a big deal. Just load the data which matches the details table data.
For example, you have two tables Country & City.

------------------------------
Country
------------------------------
CountryID | CountryName
------------------------------
1         | US
2         | UK
3         | Canada
------------------------------
City
------------------------------
CountryID CityID | CityName
------------------------------
1        |1      | New york
1        |2      | Los Angles
2        |1      | London
2        |2      | Luton
------------------------------



现在你必须编写一个查询来加载可用国家(用于下拉列表),如下所示


Now you have to write a query to load Available Countries(for Dropdown) like below

SELECT B.CountryID,A.CountryName FROM Country A, City B
WHERE A.CountryID=B.CountryID

现在它只加载有城市的国家。

Now it'll load only Countries which has cities.

------------------------------
Available Countries
------------------------------
CountryID | CountryName
------------------------------
1         | US
2         | UK
------------------------------



就是这样。


That's it.