hisham
IS-IT--Management
- Nov 6, 2000
- 194
How can I search and retrieve data from tow tables? I use the following code to search for data in the contact table in a mysql database, and search.html:
<form action="search.php" method="post" >
<table>
<td >Search: </td>
<td ><input type="text" size="15" name="word"></td>
</tr><tr>
<td colspan="2"><input type="submit" value="Search"></td>
</form>
search.php :
if (!empty($word)) {
$search = mysql_query("SELECT id,name,address FROM contact WHERE name LIKE '%$word%' OR address LIKE '%$word%'" or die ("ERROR:" . mysql_error());
$num = mysql_num_rows($search);
if ($num == 0) {
echo " Search results $word found $num results: ";
echo " Sorry no results";
} else {
echo "Search results for $word found $num results: ";
while ($row = mysql_fetch_row($search)) {
echo "<a href=\"detail.php?id=$row[0]\" class=\"search\">$row[1]</a>";
echo "$row[2]";
}
}
} else {
echo "You didn't fill in a search word.";
}
thanks in advance.
<form action="search.php" method="post" >
<table>
<td >Search: </td>
<td ><input type="text" size="15" name="word"></td>
</tr><tr>
<td colspan="2"><input type="submit" value="Search"></td>
</form>
search.php :
if (!empty($word)) {
$search = mysql_query("SELECT id,name,address FROM contact WHERE name LIKE '%$word%' OR address LIKE '%$word%'" or die ("ERROR:" . mysql_error());
$num = mysql_num_rows($search);
if ($num == 0) {
echo " Search results $word found $num results: ";
echo " Sorry no results";
} else {
echo "Search results for $word found $num results: ";
while ($row = mysql_fetch_row($search)) {
echo "<a href=\"detail.php?id=$row[0]\" class=\"search\">$row[1]</a>";
echo "$row[2]";
}
}
} else {
echo "You didn't fill in a search word.";
}
thanks in advance.