Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

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.
";
}

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.
shuterbug96 [ Do, 20 Juli 2006 17:57 ] [ ID #1398987 ]

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

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
jds [ Do, 20 Juli 2006 18:20 ] [ ID #1398988 ]

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

shuterbug96 [at] 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:
> <?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.
";
> }
>
> 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.

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.
flamer [ Fr, 21 Juli 2006 00:40 ] [ ID #1398998 ]

Re: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Flamer wrote:

> shuterbug96 [at] 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:
> > <?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.
";
> > }
> >
> > 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.
>
> 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."<br>";

and then outside of the loop echo $myqueries, now to ensure that the
page will still load stick an ' [at] ' 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.
flamer [ Fr, 21 Juli 2006 06:39 ] [ ID #1400387 ]
PHP » alt.php.sql » Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Vorheriges Thema: phpmyadmin freetext 50% threshold
Nächstes Thema: PHP Text editor ?