|
Posted by Flamer on 10/14/53 11:53
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:
> > <?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.
>
> 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 '@' 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.
Navigation:
[Reply to this message]
|