9

I'm building a search within my site. I have a problem with the DB. It's giving me this:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\searchscript\search.php on line 86

I'll show you the code section where it gives me such error

line 82: $query = "SELECT * FROM dreams WHERE titolo,titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC "; 
line 85: $numresults=mysql_query($query);
line 86: $numrows=mysql_num_rows($numresults); //error

Now I tried to see what is the problem behind the query and it's telling me this:

SELECT * FROM dreams WHERE titolo, titch LIKE "%tags%" ORDER BY id_dreams DESC 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'titch LIKE "%tags%" ORDER BY id_dreams DESC' at line 1

The code behind this is:

$query = "SELECT * FROM dreams WHERE titolo, titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC "; 
$result = mysql_query($query) or die($query."<br/><br/>".mysql_error());
2
  • have you tried your query manually..? is it working good ?? Commented Oct 14, 2011 at 10:37
  • 3
    Sick and tired of these questions. There are a million duplicates. Perform a search next time or just bother to look a little to the right, where they're all listed for you. Commented Oct 14, 2011 at 10:38

2 Answers 2

16

The mysql_query is returning a boolean value meaning the sql query is probably failing and you're getting a false returned rather than a mysql resource.

Have you checked your query?

Sign up to request clarification or add additional context in comments.

1 Comment

My problem is that the query is working when I perform it for one single field, though it returns me a boolean result and therefore False if I perform the search on 2 fields.
2

You forgot to check whether $num_results is a MySQL result resource. In this case your query errored, so it's FALSE instead.

Re-read the documentation for mysql_query and ensure you program for all possible cases.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.