Hello all . I am working on a small search for my website. It requires that i query the database and then display search results. In my database i have multiples. For example john on one row and john on the other. I want to display both of them. For now i can only display the information of one john. I don't know how to find the rest. My code looks like this.

mysql_connect("localhost","root","goingdown")or die("cannot connect"); 
	mysql_select_db("listings")or die("cannot select DB");

	$sql="SELECT * FROM data WHERE name='john' ";
	$row = mysql_fetch_array( $result );

echo "Name: ".$row['name'];
echo " Age: ".$row['age'];


So this will find john in my database, and display his name and age, i want to show both johns though, how would i do this thanks.
6 Years
Discussion Span
Last Post by urtrivedi
while ($row = mysql_fetch_array($result))
  echo 'Name: ' . $row['name'];
  echo ' Age: ' . $row['age'];

You must use loop to display the multiple result

while($row = mysql_fetch_array( $result ))
      echo "Name: ".$row['name']." ";
      echo " Age: ".$row['age']."<br>";
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.