tlavelle Posted August 17, 2007 Share Posted August 17, 2007 This code I wrote doesn't work but illustrates what I want to do while($row = mysql_fetch_row($metric_result)) { echo "<tr>"; echo "<td>".$row[0]."</td>"; echo "<td>" . $row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo "<td>".$myvalue[$row]."</td>"; echo "</tr>"; } How do I generate an index for the $myvalue[] array based on the current mysql row? Quote Link to comment https://forums.phpfreaks.com/topic/65444-solved-getting-current-row-number-mysql_fetch_row/ Share on other sites More sharing options...
lemmin Posted August 17, 2007 Share Posted August 17, 2007 Is your query only returning one result? If you change this: while($row = mysql_fetch_row($metric_result)) { to: while($row = mysql_fetch_array($metric_result)) { The code that follows will work, though I'm not exactly sure it is the values you want to return. Quote Link to comment https://forums.phpfreaks.com/topic/65444-solved-getting-current-row-number-mysql_fetch_row/#findComment-326801 Share on other sites More sharing options...
dbo Posted August 17, 2007 Share Posted August 17, 2007 Try this: $len = mysql_num_rows($metric_result); for( $i = 0; $i < $len; ++$i ) { $row = mysql_fetch_row($metric_result); echo "<tr>"; echo "<td>" . $row[0]. "</td>"; echo "<td>" . $row[1]. "</td>"; echo "<td>" . $row[2]. "</td>"; echo "<td>" . $myvalue[$i] . "</td>"; echo "</tr>"; } By using a for loop your index ($i) is your current row number. Alternatively you could just add a counter to your while loop, but I think it's pertier this way. Quote Link to comment https://forums.phpfreaks.com/topic/65444-solved-getting-current-row-number-mysql_fetch_row/#findComment-326805 Share on other sites More sharing options...
tlavelle Posted August 17, 2007 Author Share Posted August 17, 2007 Thanks...the mysql_num_rows loop did it. Now I ahve another problem : ) Quote Link to comment https://forums.phpfreaks.com/topic/65444-solved-getting-current-row-number-mysql_fetch_row/#findComment-326813 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.