Solarpitch Posted August 14, 2008 Share Posted August 14, 2008 Hi, In the below snippet of code, I'm trying to change sub1 to whatever the amount of results that are being returned. So if there are 5 results I will need to loop 5 times changing sub($i).. so sub1, sub2, sub3 etc.. It needs to be dynamic and not static. Just a little stuck on how I can do this. <?php while(($row = mysql_fetch_row($result)) != false) { echo " <div class='menutitle' onclick=\"SwitchMenu('sub1')\">".$row[1]."</div> <span class='submenu' id='sub1'>"; populate_ordering_products(); "</span>"; } } /> Quote Link to comment https://forums.phpfreaks.com/topic/119638-solved-loop-question/ Share on other sites More sharing options...
JasonLewis Posted August 14, 2008 Share Posted August 14, 2008 Like this? $i = 1; //start i at 1 while(($row = mysql_fetch_row($result)) != false) { echo "<div class='menutitle' onclick=\"SwitchMenu('sub".$i."')\">".$row[1]."</div> <span class='submenu' id='sub1'>"; populate_ordering_products(); "</span>"; $i += 1; //add one to i. } Quote Link to comment https://forums.phpfreaks.com/topic/119638-solved-loop-question/#findComment-616374 Share on other sites More sharing options...
JonnoTheDev Posted August 14, 2008 Share Posted August 14, 2008 $x = 1; while(($row = mysql_fetch_row($result)) != false) { echo " <div class='menutitle' onclick=\"SwitchMenu('sub".$x."')\">".$row[1]."</div> <span class='submenu' id='sub".$x."'>"; populate_ordering_products(); $x++; "</span>"; } Quote Link to comment https://forums.phpfreaks.com/topic/119638-solved-loop-question/#findComment-616375 Share on other sites More sharing options...
Solarpitch Posted August 14, 2008 Author Share Posted August 14, 2008 Thanks, I found another solution too by using the primary id in the table. <?php <?php while(($row = mysql_fetch_row($result)) != false) { echo " <div class='menutitle' onclick=\"SwitchMenu('sub".$row[0]."')\">".$row[1]."</div> <span class='submenu' id='sub".$row[0]."'>"; populate_ordering_products(); "</span>"; } } /> ?> Quote Link to comment https://forums.phpfreaks.com/topic/119638-solved-loop-question/#findComment-616376 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.