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>"; } Quote Link to comment 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++; } Quote Link to comment Share on other sites More sharing options...
tqla Posted July 1, 2009 Author Share Posted July 1, 2009 YES!! That works. Thanks Bendude14. 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.