简体   繁体   English

需要基于主MySql数据库中的数据是否已经存在来填充菜单的可用选项

[英]Need to populate a menu's available choices based on whether data in main MySql db already exists

I've been searching for hours. 我一直在找几个小时。 I doubt this is a unique situation - I just don't know where to look or how to build a proper Query to MySql. 我怀疑这是一种独特的情况-我只是不知道在哪里寻找或如何构建对MySql的适当查询。

Main data table is for a website CMS. 主数据表用于网站CMS。 So, there's the PAGE it's on, the SECTION of the page it shows up on, and the CONTENT (text, html, etc) 因此,有它的PAGE,它显示的页面的SECTION和CONTENT(文本,html等)

I then have two tables, one having all the available PAGE names on the site, and one with all the possible SECTION names. 然后,我有两个表,一个表具有站点上所有可用的PAGE名称,一个表具有所有可能的SECTION名称。 (used to populate the menus) (用于填充菜单)

In the CMS data New Entry page, I want the user to be able to select from drop-down menus the PAGE they want first, and (here's the tricky part) then populate the second drop-down menu with ONLY the page sections that don't already have data. 在CMS数据的“新条目”页面中,我希望用户能够从下拉菜单中选择他们想要的PAGE,然后(这是棘手的部分)然后在第二个下拉菜单中仅填充不希望使用的页面部分还没有数据。 (So they can't create a second "Index Page Main Content" record, for example). (例如,因此他们不能创建第二个“索引页面主要内容”记录)。

I've found plenty of solutions using all manner of things to dynamically fill the second menu - but no clue how to create a query that polls the main db based on the page chosen from the first menu and looks to see what sections types are still unused. 我发现了很多使用各种方法动态填充第二个菜单的解决方案-但是不知道如何创建一个查询,该查询基于从第一个菜单中选择的页面来轮询主数据库,并查看仍然是哪些节类型没用过。

As per request, http://sqlfiddle.com/#!2/736600 for the database setups. 根据要求, http: //sqlfiddle.com/#! 2/736600用于数据库设置。

See my SQLFiddle at http://sqlfiddle.com/#!2/1573b/5 . http://sqlfiddle.com/#!2/1573b/5上查看我的SQLFiddle。

CREATE TABLE a 
(
 id int auto_increment primary key, 
 page varchar(20), 
 section varchar(20),
 content varchar(30)
);

INSERT INTO a
(page, section,content)
VALUES
('home', 'main', 'hello'),
('home', 'sidebar', 'hello'),
('about', 'main', 'hello'),
('about', 'sidebar', 'hello')

List pages: select DISTINCT(page) from a; 列出页面: select DISTINCT(page) from a;

List sections: select DISTINCT(section) from a; 列出节: select DISTINCT(section) from a;

List sections for a specific page: select DISTINCT(section) from a where page = 'home' 列出特定页面的部分: select DISTINCT(section) from a where page = 'home'

You should be able to take the results of the last query, compare it to your list of sections and show only items that do not exist from the SQL query result. 您应该能够获取最后一个查询的结果,将其与部分列表进行比较,并仅显示SQL查询结果中不存在的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM