Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search and retrieve data from tow tables?

Status
Not open for further replies.

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=&quot;search.php&quot; method=&quot;post&quot; >
<table>
<td >Search: </td>
<td ><input type=&quot;text&quot; size=&quot;15&quot; name=&quot;word&quot;></td>
</tr><tr>
<td colspan=&quot;2&quot;><input type=&quot;submit&quot; value=&quot;Search&quot;></td>
</form>

search.php :
if (!empty($word)) {
$search = mysql_query(&quot;SELECT id,name,address FROM contact WHERE name LIKE '%$word%' OR address LIKE '%$word%'&quot;) or die (&quot;ERROR:&quot; . mysql_error());

$num = mysql_num_rows($search);
if ($num == 0) {
echo &quot; Search results $word found $num results: &quot;;
echo &quot; Sorry no results&quot;;
} else {
echo &quot;Search results for $word found $num results: &quot;;
while ($row = mysql_fetch_row($search)) {
echo &quot;<a href=\&quot;detail.php?id=$row[0]\&quot; class=\&quot;search\&quot;>$row[1]</a>&quot;;
echo &quot;$row[2]&quot;;
}
}
} else {
echo &quot;You didn't fill in a search word.&quot;;
}

thanks in advance.
 
Try this method:
[tt]
Code:
SELECT contact.*,contact2.*
    FROM contact LEFT JOIN contact2
    USING (name)
    WHERE((contact.name LIKE '%$word%' 
            or contact.address LIKE '%$word%') 
        OR (contact2.name LIKE '%$word%' 
            or contact2.address LIKE '%$word%')
    )
[/tt]
Chad ICQ: 54380631
online.dll
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top