tqla Posted July 1, 2009 Share Posted July 1, 2009 Hello, I wrote this to pull data from a database. I need to change the "showid" number on each loop ($f). What I am having trouble with is getting the value of $f to start at 1 and increment by 1 with every loop. As it is it shows 9999 for every loop. How can I get the for loop to work within the while loop? Thanks! $sql = "SELECT * FROM $content WHERE section_group = '$grp' ORDER BY position"; $questions2 = mysql_query($sql) or die (mysql_error()); while($row2 = mysql_fetch_array($questions2)) { // This is the showid value for ($i = 0; $i < 10000; $i++) { $f = $i; } echo "<div style=\"text-align:left;font-weight:bold;cursor:pointer\" class=\"home_cat_nav\" onclick=\"showid('"; echo $f; echo "');\">"; echo $row2['title']; echo "</div>"; } Link to comment https://forums.phpfreaks.com/topic/164400-solved-a-for-loop-inside-a-while-loop-is-it-possible/ Share on other sites More sharing options...
Bendude14 Posted July 1, 2009 Share Posted July 1, 2009 So you just want a counter inside the while loop? set a variable before the loop starts and then incrememnt inside $showid = 1 while($row2 = mysql_fetch_array($questions2)) { //loop code here //increment counter $showid++; } Link to comment https://forums.phpfreaks.com/topic/164400-solved-a-for-loop-inside-a-while-loop-is-it-possible/#findComment-867173 Share on other sites More sharing options...
tqla Posted July 1, 2009 Author Share Posted July 1, 2009 YES!! That works. Thanks Bendude14. Link to comment https://forums.phpfreaks.com/topic/164400-solved-a-for-loop-inside-a-while-loop-is-it-possible/#findComment-867177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.