PHP search from two tables

Hi There,

I am still pretty new to this, most of the stuff I have learned was shown to be by my cousin so forgive me If I am doing it wrong. Anyways I have a php search on page that search’s one table but I would like it to search two tables, is this possible and if so how would I do it?

[php]//collect
if (isset($_POST[‘search’])) {
$searchq = $_POST[‘search’];

	$query = mysql_query("SELECT * FROM Players WHERE FirstName LIKE '%$searchq%' OR LastName Like '%$searchq%' OR FullName LIKE '%$searchq%' ") or die(mysql_error());

$count = mysql_num_rows ($query);
if($count == 0){
$output = ‘There was no search results!’;
}else{
while($row = mysql_fetch_array($query)) {
$fname = $row[‘FirstName’];
$lname = $row[‘LastName’];
$PlayerID = $row[‘PlayerID’];[/php]

[code] $output .= “<a href=“cnghlplayerinfo.php?PlayerID=”.$row[‘PlayerID’].’” style=“text-decoration:none;”>’.$row[‘FirstName’]." “.$row[‘LastName’].”
";

	}
}

}

?>

Search Player [/code]

What two tables do you want it to search?

Seems like all you will need to do is modify the query below to include the second table. It’s impossible to do it for you without knowing the name of the second table and the columns in it.

[php]$query = mysql_query("SELECT * FROM Players WHERE FirstName LIKE ‘%$searchq%’ OR LastName Like ‘%$searchq%’ OR FullName LIKE ‘%$searchq%’ ") or die(mysql_error());[/php]

I am trying to Search the table goalies and colunms First, Last and FullName.

Sponsor our Newsletter | Privacy Policy | Terms of Service