Jump to content

SQL Problem


princeads

Recommended Posts

Hi guys,

 

Could anyone help with this problem - I have a MYSQL database that uses PHP to create a dynamic website. The menu is built from the database in a table called cmsmenus, with a table called cmspages that uses the cmsmenu id as a foriegn key. I've attached my sql statement below:

 

$sql = "SELECT m.id, m.label, m.link_url, m.parent_id, m.topmenu, m.leftmenu FROM cmsmenu m LEFT JOIN cmspages p ON p.menu_ID = m.id AND p.statusID = 1 ORDER BY m.parent_id, m.orderid ASC";

 

Hopefully this helps explains the scenario, at the moment all results in the cmsmenu table are retrieved which is great, but the "AND p.statusID = 1" doesn't seem to be working. Even if the corrsponding row in cmspages has value 2 the query still retrieves it, which ideally I don't want!

 

Any help on this would be great. cheers

AB

Link to comment
Share on other sites

Try putting the 1 in ''

 

$sql = "SELECT m.id, m.label, m.link_url, m.parent_id, m.topmenu, m.leftmenu FROM cmsmenu m LEFT JOIN cmspages p ON p.menu_ID = m.id AND p.statusID = '1' ORDER BY m.parent_id, m.orderid ASC";

 

See what that gives you.

Link to comment
Share on other sites

Try the join with a WHERE clause for status and also keep the 1 in '' as mentioned earlier

 

$sql = "SELECT m.id, m.label, m.link_url, m.parent_id, m.topmenu, m.leftmenu FROM cmsmenu m LEFT JOIN cmspages p ON p.menu_ID = m.id  WHERE p.statusID = '1' ORDER BY m.parent_id, m.orderid ASC"; 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.