I'm new to mysql and was wondering if someone could help me
Im using the following code on search engine on my site I have to table blog and news when i change blog to news and post to article the error disappears but when i change it back i get the Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource.

I have now idea what the error is can anyone help me much appreciated.

copy of the the query code:


include ('../config.php');

if(isset($_GET['search_term']) && isset($_GET['search_button']))
      $search_term = $_GET['search_term'];
        $first_pos = "0";

 $sql_query = mysql_query("SELECT * FROM blog WHERE MATCH(title,post) AGAINST('$search_term')");
    //additional check. Insurance method to re-search the database again in case of too many matches (too many matches cause returning of 0 results)
    if($results = mysql_num_rows($sql_query) != 0)
                $sql =  "SELECT * FROM blog WHERE MATCH(title,post) AGAINST('$search_term') LIMIT $first_pos, $RESULTS_LIMIT";
                  $sql_result_query = mysql_query($sql);         
                  $sql = "SELECT * FROM blog WHERE (title LIKE '%".mysql_real_escape_string($search_term)."%' OR post LIKE '%".$search_term."%') ";
                  $sql_query = mysql_query($sql);
                  $results = mysql_num_rows($sql_query);
                  $sql_result_query = mysql_query("SELECT * FROM blog WHERE (title LIKE '%".$search_term."%' OR post LIKE '%".$search_term."%') LIMIT $first_pos, $RESULTS_LIMIT ");

Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by Blitz-labs.com

It's because your SELECT query failed. Instead of: $sql_query = mysql_query("SELECT * FROM blog WHERE MATCH(title,post) AGAINST('$search_term')"); try using the following you you can find out WHY the error ocurred: $sql_query = mysql_query("SELECT * FROM blog WHERE MATCH(title,post) AGAINST('$search_term')")[B] or die(mysql_error())[/B] ;

Edited by hielo: n/a


I tried your suggestiona and it gave me the following error :
Can't find FULLTEXT index matching the column list.
Thanks for the suggestion hielo but the same query with the following changed
blog = news //these are tables
post = article
and the whole script works.


Thanks to everyone for trying but I have solved the problem it was a mysql table error it was to do with the way my tables were created

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.