Bricktop Posted March 6, 2008 Share Posted March 6, 2008 Hi guys, I have the following code: function menu($location = null) { $sql = mysql_query("SELECT location FROM database ORDER BY location ASC"); $locations = array(); $content .= 'menu1[0]=\'<a href="file.php?fct=showall">Show All</a>\''; while ($a = mysql_fetch_array($sql)) { $num = 0; ++$num; if (!in_array($a['location'],$locations)) { $content .= 'menu1['.$num.']=\'<a href="file.php?fct=showstuff&location='.$a['location'].'">'.$a['location'].'</a>\''; $locations[] = $a['location']; } } return $content; } Basically, it's a menu I've built which takes the locations from a database and lists them. This code works fine. However, in this version you can see I am trying to auto increment $num every time a location is output. I cannot get it to work, all locations come out as the same number - 1. What am I doing wrong please? Each number just needs to output in order everytime a location is listed, e.g 1, 2, 3, 4, 5 etc etc Thanks, hope this makes sense Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 6, 2008 Share Posted March 6, 2008 You're setting $num to zero each time you enter the loop. Quote Link to comment Share on other sites More sharing options...
Bricktop Posted March 6, 2008 Author Share Posted March 6, 2008 Hi, Thanks, sorry this is a little new for me, how do I fix this please? If you could give a code snippet it would be much appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
Bricktop Posted March 6, 2008 Author Share Posted March 6, 2008 lol sry just worked it out - so obvious! lol thanks again - i need more coffee Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 6, 2008 Share Posted March 6, 2008 If you need more coffee then likely you need more sleep. Cure the disease, not the symptoms. 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.