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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.