Posted by shuterbug96 on 10/07/31 11:53
I am trying to write a search string for a magazine site. it accesses
the database but I am not getting results instead I am getting this:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in
/www/currenthistory.com/htdocs/preview/search-results.php on line 32
here are the lines:
<?php
$name = $_POST['keywords'];
$name_arr = explode(' ', $name);
$search_result = '';
foreach($name_arr as $key => $name)
{
$query="SELECT * FROM Articls WHERE";
$query.=" Keywords LIKE '%$name%'";
$query.=" OR Title LIKE '%$name%'";
$query.=" OR Author LIKE '%$name%' ORDER BY title";
$result_arr[$key]=mysql_db_query("currenthistorydb", $query);
$num_rows_arr[$key]=mysql_num_rows($result_arr[$key]);
$search_result.= "Found $num_rows_arr[$key] results for the term
$name.<br />";
}
mysql_close();
echo($search_result);
echo '<b><center><font size="4" color="#FF0000">Search
Result</font></center></b><br><br>';
foreach($result_arr as $key => $result)
{
$i=0;
while ($i < $num_rows_arr[$key])
{
$row = mysql_fetch_row($result);
$search_term = $name_arr[$key];
$authors = $row[1];
$title = $row[2];
$source = $row[3];
echo "<b>Search Term:</b> $search_term<br><b>Author:</b>
$authors<br><b>Title:</b> $title<br><b>Source:</b>
$source<br><br><hr><br>";
$i++;
}
}
?>
why is it giving me this error?
any help will be much appreciated.
Navigation:
[Reply to this message]
|