Hi all,

I AM TRYING TO CREATE A SEARCH ENGINE USING PHP AND MYSQL.
I've been hitting the same problem over and over in my development. Sometimes when i do a MySQL query I keep getting the error
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\searchengine\search.php on line 68

I don't understand why. What does this error mean, am I doing something wrong?

I'm using php 5.3, it's definitely not my mysql statement. I'm lost >.<

I even simplify my query code and still the same problem. The general code look something like this:

//echo outconstruct
  $constructx = "SELECT * FROM searchengine WHERE $construct";
  
  $construct = "SELECT * FROM searchengine WHERE $construct LIMIT $s,$e";
  $run = mysql_query($constructx);
  
  $foundnum = mysql_num_rows($run);


  $run_two = mysql_query("$construct");
  
  if ($foundnum==0)
   echo "No results found for <b>$search</b>";
  else
  {

I would have to disagree that it definitely is not a problem with the query - I actually think that is the likeliest cause. The reason I believe this is because I've seen this warning many times myself, and it's always been something wrong with the query itself. If the query breaks for some reason (maybe you refer to a field which doesn't exist for example), then what happens is instead of returning a resource, FALSE is returned.

What I would recommend is echoing the query exactly as it is prior to being passed to mysql_query() - then go into phpmyadmin and try to execute it. It will probably point out what is wrong with the query.

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.