CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge -> Tips & Solutions

 MySQL dynamic menu trick

Print topic Send  topic

Author Message
Vector

Posts: 1
Posted: 10/12/2016, 11:31 AM Quote message

So, I had a basic horizontal menu, being driven by a MySQL table. Pretty simple to do.

But, I suddenly had an issue, where files uploaded (another page) that push their names and a description to another table, had to become part of the menu. This was in 2 places (that is 2 types of uploaded files, in terms of their general category.)

So, I engineered a SQL query for the menu, that makes the files and their links show up, dynamically.

The main menu table is still used, and the query forges the other choices. I sometimes use Active as a integer flag to choose things I want to turn off and on as features. This can be useful in building things, or letting users turn on and off things.

I replaced the query to the table, with this sql query in the menu object on the page. It makes it's own Id numbers, so you have to set up your actual Menu table so that the first part of the sequence agrees with these dynamically assigned numbers. After that, the forging in the sub-queries manages to lie to the menu, and give it what you want. In this case, the uploaded file descriptions and the links to the targets.

select @r := @r+1 as Id, z.* from(

SELECT Menu, Link, Level, Tier, Active
FROM Menu

UNION

SELECT Menu, Link, Level, Tier, Active FROM (

SELECT
Description as Menu,
CONCAT("documents/",Link) as Link,
3 as 'Level',
1 as Tier,
1 as Active
FROM Documents
ORDER BY Description) x

UNION

SELECT Menu, Link, Level, Tier, Active FROM (
SELECT
Description as Menu,
CONCAT("profiles/",Link) as Link,
4 as 'Level',
1 as Tier,
1 as Active
FROM Profiles
Order by Description) y

)z, (select @r:=0)y;

View profile  Send private message

Add new topic Reply to topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.