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' ";
	$result=mysql_query($sql);     
	$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.

Recommended Answers

All 2 Replies

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>";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.