dianikol85 Posted December 18, 2010 Report Share Posted December 18, 2010 (edited) Hi to all. I have this function to display a list from a db and then a weird thing is happening. It increases the $i counter 2 steps instead of 1... The sql query runs ok in phpadmin. Then I echo the $i counter within the for loop and it prints 0,2,4.... Any suggestions??? By the way i don't use mysqli. Boss's choise. I can't help it, hehe. and the language in the <th> is greek so don't bother... function getCustomersList() { $sql = "select USER_ID, USER_NAME, USER_LNAME, USER_MAIL, USER_ADDRESS from user where USER_GROUP = '2' order by USER_ID desc limit 5"; $res = mysql_query($sql); $num_rows = mysql_num_rows($res); if ($num_rows > 0) { echo "<table cellpadding='0' cellspacing='0' class='table_info'> <thead> <th>Κωδ. πελάτη</th> <th>Ονοματεπώνυμο</th> <th>Διεύθυνση</th> <th>E - mail</th> </thead> <tbody>"; for ($i = 0; $i < $num_rows; $i++) {echo $i; $row = mysql_fetch_array($res); echo "<tr>"; echo "<td><a href='users/edit_user.php?USER_ID=$row[uSER_ID]>$row[uSER_ID]</a></td>"; echo "<td>$row[uSER_NAME] $row[uSER_LNAME]</td>"; echo "<td>$row[uSER_ADDRESS]</td>"; echo "<td>$row[uSER_MAIL]</td>"; echo "</tr>"; } echo " </tbody> </table>"; } else { echo "<div id='empty'>Δεν υπάρχουν καταχωρημένοι πελάτες</div>"; } } Edited December 18, 2010 by dianikol85 Quote Link to comment Share on other sites More sharing options...
falkencreative Posted December 18, 2010 Report Share Posted December 18, 2010 I'm not sure why you the $i variable is incrementing twice -- I'm not seeing any code that should do that. However, maybe adjust your code to use a while loop, rather than a for loop. Maybe something like this: (not tested, since I obviously don't have your database setup in place to check this) function getCustomersList() { $sql = "select USER_ID, USER_NAME, USER_LNAME, USER_MAIL, USER_ADDRESS from user where USER_GROUP = '2' order by USER_ID desc limit 5"; $res = mysql_query($sql); $num_rows = mysql_num_rows($res); if ($num_rows > 0) { echo "<table cellpadding='0' cellspacing='0' class='table_info'> <thead> <th>Κωδ. πελάτη</th> <th>Ονοματεπώνυμο</th> <th>Διεύθυνση</th> <th>E - mail</th> </thead> <tbody>"; while($row = mysql_fetch_array( $res )) { echo "<tr>"; echo "<td><a href='users/edit_user.php?USER_ID=$row[uSER_ID]>$row[uSER_ID]</a></td>"; echo "<td>$row[uSER_NAME] $row[uSER_LNAME]</td>"; echo "<td>$row[uSER_ADDRESS]</td>"; echo "<td>$row[uSER_MAIL]</td>"; echo "</tr>"; } echo " </tbody> </table>"; } else { echo "<div id='empty'>Δεν υπάρχουν καταχωρημένοι πελάτες</div>"; } } Quote Link to comment Share on other sites More sharing options...
BeeDev Posted December 20, 2010 Report Share Posted December 20, 2010 Have you tried using another variable? like $q or $j or $v or something like that Quote Link to comment Share on other sites More sharing options...
dianikol85 Posted December 20, 2010 Author Report Share Posted December 20, 2010 (edited) Have you tried using another variable? like $q or $j or $v or something like that yes i did. maybe it has to do with some php's core variables mix up. I don't know. Never happened before Edited December 20, 2010 by dianikol85 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.
Note: Your post will require moderator approval before it will be visible.