wmguk Posted July 5, 2008 Share Posted July 5, 2008 Hey, I have existing code, and I've been trying to get this to display $r as the row number - ie if there are 4 results found the $r = 1 on the first, 2 on the second etc etc, but I can only get it to display either 2, or 1234, not loop through... Can anyone see my mistake? <?PHP while ($row=mysql_fetch_assoc($countresult)) { $r = 1; $r <= $used; $r++ ; ?> <tr><td class="rightmenu">Size:td> <td width="5"> </td> <td><? echo "<input type='text' class='boxes' name='size_$r' value='"; echo $row['size']; echo "'>"; ?> </td> <td class="rightmenu">Cost:</td> <td width="5"> </td> <td><? echo "<input type='text' class='boxes' name='cost_$r' value='"; echo $row['cost']; echo "'>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113369-solved-get-r-loop-to-increment-number/ Share on other sites More sharing options...
wildteen88 Posted July 5, 2008 Share Posted July 5, 2008 Well this bunch of code is not quote right: $r = 1; $r <= $used; $r++ ; Your set $r to 1 then you are incorrectly comparing to see if $r is then or equal to $used (which doesn't seem to exis), if it is increment $r The first line should be outside of the while loop. The next two lines should be: if($r <= $used) $r++; Quote Link to comment https://forums.phpfreaks.com/topic/113369-solved-get-r-loop-to-increment-number/#findComment-582442 Share on other sites More sharing options...
wmguk Posted July 5, 2008 Author Share Posted July 5, 2008 Well this bunch of code is not quote right: $r = 1; $r <= $used; $r++ ; Your set $r to 1 then you are incorrectly comparing to see if $r is then or equal to $used (which doesn't seem to exis), if it is increment $r The first line should be outside of the while loop. The next two lines should be: if($r <= $used) $r++; Sorry, $used is set before the head of the page <?PHP $refnum = $_GET['refnum']; include "scripts/connection.php"; $countresult = mysql_query("SELECT * FROM sizes WHERE originalprod = '$refnum' "); $used = mysql_num_rows($countresult); $count = 10 ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/113369-solved-get-r-loop-to-increment-number/#findComment-582447 Share on other sites More sharing options...
wmguk Posted July 5, 2008 Author Share Posted July 5, 2008 Excellent thank you, thats solved it!! <?PHP $r = 0; while ($row=mysql_fetch_assoc($countresult)) { if($r <= $used) $r++; ?> <tr><td class="rightmenu">Size:<td> <td width="5"> </td> <td><? echo "<input type='text' class='boxes' name='size_$r' value='"; echo $row['size']; echo "'>"; ?> </td> <td class="rightmenu">Cost:</td> <td width="5"> </td> <td><? echo "<input type='text' class='boxes' name='cost_$r' value='"; echo $row['cost']; echo "'>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113369-solved-get-r-loop-to-increment-number/#findComment-582451 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.