FishSword Posted June 22, 2013 Share Posted June 22, 2013 I have a problem with my code. What is the best way to display all sub pages for a parent page regardless of whether or not you are viewing the parent or child pages? If a different parent is chosen, then the child pages of the previously selected parent should be hidden.All pages have a id vairable in the URL that is available using $_GET['id'].My MYSQL DB looks like this. CREATE TABLE IF NOT EXISTS `pages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) NOT NULL, `parent` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8; With the code I have currently, the child pages display if you are on the parent page, but as soon as you jump to any of the child pages, the child pages disappear. $gParents = mysql_query('SELECT * FROM db.pages WHERE parent = 0'); while($parents = mysql_fetch_assoc($gParents)) { echo '<a href="?id='.$parents['id'].'">'.$parents['title'].'</a><br />'; $qChilds = mysql_query('SELECT * FROM db.pages WHERE parent = '.$parents['id'].' AND parent = '.$_GET['id']); while($childs = mysql_fetch_assoc($qChilds)) { echo '<a href="?id='.$childs['id'].'">'.$childs['title'].'</a><br />'; } } Quote Link to comment Share on other sites More sharing options...
boompa Posted June 22, 2013 Share Posted June 22, 2013 Does AND here really make sense? SELECT * FROM db.pages WHERE parent = '.$parents['id'].' AND parent = '.$_GET['id'] Quote Link to comment Share on other sites More sharing options...
FishSword Posted June 22, 2013 Author Share Posted June 22, 2013 Thanks for your response, it's much appreciated. My aim is to create a vertical page menu using <ul>'s. Upon a user clicking a parent menu item, they will taken to a different page where the content of the selected page will be displayed. Any child pages will be displayed as <li>'s of a child <ul> in the menu, underneath the relevent paten in the menu. Child pages need to be visible only when the parent page, or child pages belonging to the parent have been selected. I'm guessing I will need to check if the user is in a parent or child page of the parent, in order to show any relevent child pages? Quote Link to comment Share on other sites More sharing options...
FishSword Posted June 25, 2013 Author Share Posted June 25, 2013 Does that make sense? Can anyone help with this? Quote Link to comment Share on other sites More sharing options...
FishSword Posted June 29, 2013 Author Share Posted June 29, 2013 I am still stuck with this. I have attach a .zip file containing what I am trying to achieve. Example.zip Quote Link to comment Share on other sites More sharing options...
vpros Posted July 3, 2013 Share Posted July 3, 2013 I am still stuck with this. I have attach a .zip file containing what I am trying to achieve. i cannot send you a msg what is email id.... Thanks Ranjit Quote Link to comment Share on other sites More sharing options...
FishSword Posted July 6, 2013 Author Share Posted July 6, 2013 (edited) Hi vpros, I have sent you a PM. With the same title as this thread! Cheers, FishSword Edited July 6, 2013 by FishSword Quote Link to comment Share on other sites More sharing options...
thara Posted July 6, 2013 Share Posted July 6, 2013 I didn't see any php code in your attached files' Quote Link to comment Share on other sites More sharing options...
FishSword Posted July 25, 2013 Author Share Posted July 25, 2013 These isn't any. The attached file is to demonstrate what I'm trying to do. All the code I have so far has been posted in this thread. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.