Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
am 20.07.2006 17:57:11 von shuterbug96
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:
$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.
";
}
mysql_close();
echo($search_result);
echo '
Search
Result
';
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 "Search Term: $search_term
Author:
$authors
Title: $title
Source:
$source
";
$i++;
}
}
?>
why is it giving me this error?
any help will be much appreciated.
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
am 20.07.2006 18:20:00 von jds
On Thu, 20 Jul 2006 08:57:11 -0700, shuterbug96 wrote:
> Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in
It means exactly what it says. The supplied argument is not a valid mysql
resource.
It might be nice of you to tell us which line is line 32.
--
JDS
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
am 21.07.2006 00:40:15 von flamer
shuterbug96@gmail.com wrote:
> 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:
>
>
> $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.
";
> }
>
> mysql_close();
>
> echo($search_result);
>
> echo '
Search
> Result
';
>
> 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 "Search Term: $search_term
Author:
> $authors
Title: $title
Source:
> $source
";
>
> $i++;
> }
> }
>
> ?>
>
>
> why is it giving me this error?
>
> any help will be much appreciated.
Is this line meant to have this spelling:
$query="SELECT * FROM Articls WHERE";
i think the real issue here is that mysql is not getting any results,
however good code should be able to handle that without creating an
error, like first checking if results where found, so after your select
statement if (!empty($mysql_query)) {//everything in here} else
{//sorry there was a problem accessing the database}
Flamer.
Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
am 21.07.2006 06:39:13 von flamer
Flamer wrote:
> shuterbug96@gmail.com wrote:
>
> > 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:
> >
> >
> > $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.
";
> > }
> >
> > mysql_close();
> >
> > echo($search_result);
> >
> > echo '
Search
> > Result
';
> >
> > 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 "Search Term: $search_term
Author:
> > $authors
Title: $title
Source:
> > $source
";
> >
> > $i++;
> > }
> > }
> >
> > ?>
> >
> >
> > why is it giving me this error?
> >
> > any help will be much appreciated.
>
> Is this line meant to have this spelling:
> $query="SELECT * FROM Articls WHERE";
>
> i think the real issue here is that mysql is not getting any results,
> however good code should be able to handle that without creating an
> error, like first checking if results where found, so after your select
> statement if (!empty($mysql_query)) {//everything in here} else
> {//sorry there was a problem accessing the database}
>
> Flamer.
actually disregard the last part of that post i had misread the error
msg you were recieving, thats telling you have a syntax error in your
sql, what i would recommend,is because your looping that you actually
see what you are trying to query, so in that loop i would do:
$myqueries .= $query."
";
and then outside of the loop echo $myqueries, now to ensure that the
page will still load stick an '@' in front of your mysql queries just
for th etime being, that surpresses any errors and will continue to
load the page and let you see your $myqueries output.
Flamer.