White_Lily Posted October 4, 2012 Share Posted October 4, 2012 Hi, I tried writing some code for my navigation menu to make it easier on my part (with creating the site etc). I have written this so far: <?php $nav = select("*", "navigation", NULL, NULL, NULL); $num = mysql_num_rows($nav); $get = mysql_fetch_assoc($nav); $filename = file_exists($_SERVER["DOCUMENT_ROOT"]."forum/".$get["file_path"]); if($num > 0){ while($get = mysql_fetch_assoc($nav)){ if($filename){ $path = $GLOBALS["siteUrl"].$get["file_path"]; echo '<li><a href="'.$path.'">'.$get["page_name"].'</a></li>'; } } }else{ echo "<li>Could not find a navigation menu.</li>"; } ?> Problem is, even though there is an entry in the database (to a page that DOES exist) nothing shows in the navigation area, can't think why. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/ Share on other sites More sharing options...
cyberRobot Posted October 4, 2012 Share Posted October 4, 2012 Have you tried turning on all errors and warnings? <?php error_reporting(E_ALL); ini_set('display_errors', 1); //...your code goes after this point ?> Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382638 Share on other sites More sharing options...
KevinM1 Posted October 4, 2012 Share Posted October 4, 2012 Is select() a custom function? Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382639 Share on other sites More sharing options...
White_Lily Posted October 4, 2012 Author Share Posted October 4, 2012 i have a php.ini file that has display errors turned on and error reporting to E_ALL, Yes select() is a custom funtion and is well with that as the rest of the site doesnt have a problem with it. Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382640 Share on other sites More sharing options...
cyberRobot Posted October 4, 2012 Share Posted October 4, 2012 Have you checked if the variables contain values you would expect? For example, you said the code doesn't display anything...does $num indicate results were found in the database? Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382641 Share on other sites More sharing options...
cyberRobot Posted October 4, 2012 Share Posted October 4, 2012 Also, this might be a silly question, but did you establish a connection to the MySQL database? Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382645 Share on other sites More sharing options...
White_Lily Posted October 4, 2012 Author Share Posted October 4, 2012 I ehcoed $filename, the path(s) were correct, $num echos "1" which is correct due to there only being 1 row in the database, if i use a while and echo $get["file_path"] and $get["page_name], they are also correct... no errors show on the screen. Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382646 Share on other sites More sharing options...
White_Lily Posted October 4, 2012 Author Share Posted October 4, 2012 Like with the select function - the rest of the site has NO problem with the function. Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382647 Share on other sites More sharing options...
trq Posted October 4, 2012 Share Posted October 4, 2012 Have you tried putting some debug statement into your code to see what conditions are failing? Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382648 Share on other sites More sharing options...
White_Lily Posted October 4, 2012 Author Share Posted October 4, 2012 I echoed everything that should return any form of number(s) or word(s) and everything is correct... i don't quite understand why its not doing what ive asked it to do... Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382649 Share on other sites More sharing options...
PFMaBiSmAd Posted October 4, 2012 Share Posted October 4, 2012 Your code makes no logical sense. You are fetching the first row from the result set before the start of the while loop. If there's only one row, the while loop will be skipped over and if there is more than one row, the first one won't be present inside of the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382650 Share on other sites More sharing options...
trq Posted October 4, 2012 Share Posted October 4, 2012 You said you have echo'ed $filename and that the path was correct. That makes little sense. $filename holds a boolean value. What does var_dump($filename) have to say? Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382651 Share on other sites More sharing options...
cyberRobot Posted October 4, 2012 Share Posted October 4, 2012 It looks like you're getting the data twice: <?php $get = mysql_fetch_assoc($nav); //... while($get = mysql_fetch_assoc($nav)){ //... ?> So basically the first entry is ignored. Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382652 Share on other sites More sharing options...
White_Lily Posted October 4, 2012 Author Share Posted October 4, 2012 Sorted - PFMaBiSmAd & cyberRobot were correct, the first entry was being ignored didn't even relize i had called the same query twice lol Quote Link to comment https://forums.phpfreaks.com/topic/269071-coding-problem-for-navigation/#findComment-1382653 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.