I have several tables. They look similar to the one below:
table1
+---------------|---------------|----------------|----------|---------+
| archive_id | lastname | firstname | state | etc... |
+---------------|---------------|---------------|-----------|---------+
| 100 | Jones | George | WV | etc... |
| 101 | Doe | John | IN | etc... |
+---------------|---------------|----------------|----------|----------+
table2
+---------------|---------------|----------------|----------|---------+
| archive_id | lastname | firstname | state | etc... |
+---------------|---------------|----------------|----------|---------+
| 100 | Frito | Lay | NY | etc... |
| 101 | Doe | Jane | NE | etc... |
+---------------|---------------|----------------|----------|----------+
I want to run a search through all the tables
<?
$var = @$_GET['query'] ;
$trimmed = trim($var);
$limit=10;
if ($trimmed == "")
{
echo "<div align=center><br><br>Please enter a search word.<br><br></div>";
exit;
}
if ($trimmed == "Type Surname Here")
{
echo "<div align=center><br><br>Please enter a search word.<br><br></div>";
exit;
}
if (!isset($var))
{
echo "<br><br>We do not seem to have a search parameter!<br><br>";
exit;
}
//Here is where my problem begins.
//This works if I only had one table:
//$sql = "SELECT * FROM table1 WHERE lastname
// LIKE '%$trimmed%'";
// but this doesn't:
$sql = "SELECT * FROM table1, table2 WHERE lastname
LIKE '%$trimmed%'";
$numresults=mysql_query($sql);
$numrows=mysql_num_rows($numresults);
if ($numrows == 0)
{
echo "<b>Results</b>";
echo "<p align=center>Sorry, your search: "" . $trimmed . "" returned zero results.</p>";
exit;
}
if (empty($s)) {
$s=0;
}
$sql .= " limit $s,$limit";
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute the query.");
?>
I have looked through many forums but they don't seem to work with what I am trying to accomplish. Please understand that I am new to this and need lots of guidance.