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:

<?php

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

$RESULTS_LIMIT=10;
if(isset($_GET['search_term']) && isset($_GET['search_button']))
{
      $search_term = $_GET['search_term'];
    if(!isset($first_pos))
    {
        $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);         
            }
    else
            {
                  $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 ");
            }
}
?>

Recommended Answers

All 3 Replies

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] ;

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.