Hi, I'm running into a small problem. I want to select the title, address, and description from three different tables. So heres what I came up with.
<form name="form" id="searchform" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" id="s" name="searchdata" value="<?php if(isset($_POST['searchdata'])) echo htmlspecialchars($_POST['searchdata'], ENT_QUOTES); ?>" />
<input type="submit" name="Submit" value="Search" />
<input type="hidden" name="submitted" value="TRUE" /></p>
</form>
<?php
//create short variable names
if (isset($_POST['submitted'])) {
include('database.php');
if (empty($_POST['searchdata'])) {
echo '<p><font color="red">You need to enter search term.</font></p>';
} else {
$searchterm = mysql_real_escape_string(htmlspecialchars($_POST['searchdata'], ENT_QUOTES));
}
if ($searchterm) {
$query =("SELECT title, address, description FROM headlines, articles, casestudies WHERE title LIKE '%$searchterm%' ORDER BY `date` DESC LIMIT 0, 40") or die(mysql_error());
//query DB
$result = mysql_query($query);
//get number or rows
$num_rows = mysql_num_rows($result);
echo '<p><b>Number of items found: '.$num_rows.'</b></p>';
while ($s = mysql_fetch_array($result)){
//Variables
$info .="";
}
echo $info;
}
}
?>
The code works when I'm only selecting from one table but as soon as I add two more tables headlines, articles, casestudies it gives off warnings
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\blabla\search.php on line 30
Number of items found:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\blabla\search.php on line 33
How would I select more then one table?