Hi, I have made a script to search my database. But when I execute it, it shows only one result. I even checked the database but there were many entries like this.
here's the code...
<?php
// Made by Shahbaz Singh July 2011. All Rights Reserved. Webdhaba.in
$q = $_GET["q"];
$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "";
// Place the password for the MySQL database here
$db_pass = "";
// Place the name for the MySQL database here
$db_name = "test";
// Run the connection here
mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("$db_name") or die ("no database");
$sql = mysql_query("SELECT * FROM people WHERE name LIKE '%$q%'");
$num_results = 0;
while($row = mysql_fetch_array($sql))
{
$num_results++;
$name = $row["name"];
$id = $row["id"];
$default_pic = "people/$id/image01.jpg";
$no_pic = "people/0/no_image_pic.jpg";
if (file_exists($default_pic)) {
$image = "$default_pic"; } else {
$image = "$no_pic";
}
}
if($num_results == 0)
{
$output = "<table border='0' width='100%' cellspacing='0' cellpadding='0' >
<tr>
<td colspan='2' height='24' >
<p align='center'><b><font face='Arial' size='2'>Search Results</font></b></td>
</tr>
<tr>
<td align='center' width='100%' >
<font face='Arial' size='2'><br><br><br>Sorry, no results could be found.
</font></b></td>
</tr>
</table>";
} else {
$output = "<table border='0' width='100%' cellspacing='0' cellpadding='0' >
<tr>
<td colspan='2' height='24' >
<p align='center'><b><font face='Arial' size='2'>Search Results</font></b></td>
</tr>
<tr>
<td width='67' >
<b><font face='Arial' size='2'>
<img border='0' src='$image' width='86' height='86'></font></b></td>
<td width='967' >
<b><font face='Arial' size='2'>
<a href='people.php?id=$id'>
<span style='text-decoration: none'>$name
</span></a></font></b></td>
</tr>
</table>";
}
?>