CanMan2004 Posted January 2, 2007 Share Posted January 2, 2007 Hi allI have a simply query which looks like[code]<?$sql = mysql_query("SELECT * FROM name")or die(mysql_error());while($row = mysql_fetch_array($sql)){$id = $row['id'];$names = $row['names'];?><? print $names; ?><br><?}?>[/code]it returns a list of names, this looks likeDaveSarahJohnHarryVickyHow can I place a number next to each one, counting from 1 upwards, so the results would look like1 Dave2 Sarah3 John4 Harry5 VickyIs this possible?Thanks in advanceEd Link to comment https://forums.phpfreaks.com/topic/32551-solved-numbers-next-to-results/ Share on other sites More sharing options...
AndyB Posted January 2, 2007 Share Posted January 2, 2007 [code]php<?$sql = mysql_query("SELECT * FROM name") or die(mysql_error());$i = 0;while($row = mysql_fetch_array($sql)) { $id = $row['id']; // who cares? $i++; echo $i. " ". $row['names']. "<br>";}[/code] Link to comment https://forums.phpfreaks.com/topic/32551-solved-numbers-next-to-results/#findComment-151344 Share on other sites More sharing options...
taith Posted January 2, 2007 Share Posted January 2, 2007 [code]<?$sql = mysql_query("SELECT * FROM name")or die(mysql_error());while($row = mysql_fetch_array($sql)){ echo $row['id'].' '.$row['names'].'<br>';}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32551-solved-numbers-next-to-results/#findComment-151345 Share on other sites More sharing options...
kenrbnsn Posted January 2, 2007 Share Posted January 2, 2007 Yes, this is simple PHP. Do you want to print out the $id, which you are retrieving but not using, or just a simple counter?Echoing the $id:[code]<?php$q = "SELECT * FROM name";$sql = mysql_query($q)or die("Problem with the query: $q<br>" . mysql_error());while($row = mysql_fetch_array($sql)){ $id = $row['id']; $names = $row['names']; echo $id . ' ' . $names . '<br>';}?>[/code]A simple counter:[code]<?php$q = "SELECT names FROM name";$sql = mysql_query($q)or die("Problem with the query: $q<br>" . mysql_error());$i = 1;while($row = mysql_fetch_array($sql)){ $names = $row['names']; echo $i++ . ' ' . $names . '<br>';}?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/32551-solved-numbers-next-to-results/#findComment-151347 Share on other sites More sharing options...
CanMan2004 Posted January 2, 2007 Author Share Posted January 2, 2007 thanks everyone Link to comment https://forums.phpfreaks.com/topic/32551-solved-numbers-next-to-results/#findComment-151360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.