Jump to content

[SOLVED] numbering result rows


tekrscom

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/55495-solved-numbering-result-rows/
Share on other sites

<?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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.