0

This is an example I have grabbed from W3School, and for the purpose of my question, I have modified it and put in the code here:

<?php
// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM example") 
or die(mysql_error());  

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	
	echo $row['name'] . " " . $row['age'] . "<br />"; 
} 

?>

Does anyone know how I can print out the row number of each entry here. Say, if the mysql_num_rows() of the query is 3, then it would print something out like

1 David 24
2 Sam 25
3 Seth 20

How can I do that?
Thanks for your help.

Edited by ajwei810192: n/a

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by rajarajan07
0
$count=0;
while($row = mysql_fetch_array( $result )) {
	$count=$count+1;
	echo $count . " " . $row['name'] . " " . $row['age'] . "<br />"; 
}
0
$count=0;
while($row = mysql_fetch_array( $result )) {
	$count=$count+1;
	echo $count . " " . $row['name'] . " " . $row['age'] . "<br />"; 
}

So, there is no SQL statement that is going to work what I want here?
Just want to make sure.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.