tekrscom Posted June 13, 2007 Share Posted June 13, 2007 Hi, I think I'm having a bit of a looping issue... I need to number a number on every row result, but what I am getting is the amount of result rows multiplied times how many results there are... $query = mysql_query("SELECT MTES_direct_sub_task_id, MTES_direct_sub_task FROM MTES_direct_sub_tasks WHERE MTES_direct_task = '$_SESSION[task]'"); while ($row = mysql_fetch_array($query)) { $count = mysql_num_rows($query); $count = $count + 1; for($i = 1; $i < $count; $i++) echo ' <tr> <td> <input type="hidden" name="MTES_direct_sub_task" value="', $row[MTES_direct_sub_task], '"><input type="hidden" name="count" value="', $i, '"> <input type="text" name="hours" size="4"> ', $row[MTES_direct_sub_task], ' </td> </tr> '; } Any ideas on what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/55495-solved-numbering-result-rows/ Share on other sites More sharing options...
ToonMariner Posted June 13, 2007 Share Posted June 13, 2007 <?php $query = mysql_query("SELECT MTES_direct_sub_task_id, MTES_direct_sub_task FROM MTES_direct_sub_tasks WHERE MTES_direct_task = '$_SESSION[task]'"); $i = 0; while ($row = mysql_fetch_array($query)) { ?> <tr> <td> <input type="hidden" name="MTES_direct_sub_task" value="<?php echo $row[MTES_direct_sub_task];?>"> <input type="hidden" name="count" value="<?php echo $i++;?>"> <input type="text" name="hours" size="4" value="<?php echo $row[MTES_direct_sub_task]; ?>"> </td> </tr> <?php } ?> try that... Quote Link to comment https://forums.phpfreaks.com/topic/55495-solved-numbering-result-rows/#findComment-274236 Share on other sites More sharing options...
tekrscom Posted June 13, 2007 Author Share Posted June 13, 2007 You're a genius! Thank you very much for your help, it is most appreciated... Quote Link to comment https://forums.phpfreaks.com/topic/55495-solved-numbering-result-rows/#findComment-274237 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.