6 Replies - 2551 Views - Last Post: 29 December 2011 - 10:55 AM Rate Topic: -----

#1 afshandc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-December 11

Warning: mysql_num_rows() expects parameter 1 to be resource,

Posted 29 December 2011 - 10:26 AM

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\New folder\search.php on line 33
guys im getting this error


<?php error_reporting (E_ALL ^ E_NOTICE); ?>
<?php

$button = $_GET ['submit'];
$search = $_GET ['search']; 

if(!$button)
echo "you didn't submit a keyword";
else
{
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
mysql_connect("localhost","root","");
mysql_select_db("db1131690");

$search_exploded = explode (" ", $search);

foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="keywords LIKE '%$search_each%'";
else
$construct .="AND keywords LIKE '%$search_each%'";

}

$construct ="SELECT * FROM players WHERE $construct";
$run = mysql_query($construct);

$foundnum = mysql_num_rows($run);

if($foundnum==0)

echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. 
Try more general words. for example: If you want to search 'how to create a website' 
then use general keyword like 'create' 'website'</br>2. Try different words with similar
 meaning</br>3. Please check your spelling";
else
{
echo "$foundnum results found !<p>";

while($runrows = mysql_fetch_assoc($run))

{
$title = $runrows ['title'];
$desc = $runrows ['description'];
$url = $runrows ['url'];

echo "
<a href='$url'><b>$title</b></a><br>
$desc<br>
<a href='$url'>$url</a><p>
";

}
}

}
}

?>



Is This A Good Question/Topic? 0
  • +

Replies To: Warning: mysql_num_rows() expects parameter 1 to be resource,

#2 no2pencil  Icon User is offline

  • Original Digital Gansta
  • member icon

Reputation: 4465
  • View blog
  • Posts: 24,913
  • Joined: 10-May 07

Re: Warning: mysql_num_rows() expects parameter 1 to be resource,

Posted 29 December 2011 - 10:29 AM

Validate your results :

$run = mysql_query($construct);
if(!$run) {
  echo "The following SQL failed : $construct";
}

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5669
  • View blog
  • Posts: 22,517
  • Joined: 23-August 08

Re: Warning: mysql_num_rows() expects parameter 1 to be resource,

Posted 29 December 2011 - 10:33 AM

Even better, learn to SEARCH the forum. Look at the bottom of your topic:

Attached Image

See how many times this has been asked before? You could have saved yourself -- and the other users -- some time by putting in a little effort and searching for the answer prior to asking.
Was This Post Helpful? 0
  • +
  • -

#4 afshandc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-December 11

Re: Warning: mysql_num_rows() expects parameter 1 to be resource,

Posted 29 December 2011 - 10:39 AM

now im getting this :o

The following SQL failed : SELECT * FROM players WHERE keywords LIKE '%Van persie%'
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\New folder\search.php on line 36
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9037
  • View blog
  • Posts: 33,521
  • Joined: 27-December 08

Re: Warning: mysql_num_rows() expects parameter 1 to be resource,

Posted 29 December 2011 - 10:42 AM

View Postno2pencil, on 29 December 2011 - 12:29 PM, said:

Validate your results :

$run = mysql_query($construct);
if(!$run) {
  echo "The following SQL failed : $construct";
}

Or better yet, use the mysql_error() function is the query fails so you can see what the problem with your query.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Original Digital Gansta
  • member icon

Reputation: 4465
  • View blog
  • Posts: 24,913
  • Joined: 10-May 07

Re: Warning: mysql_num_rows() expects parameter 1 to be resource,

Posted 29 December 2011 - 10:47 AM

View Postafshandc, on 29 December 2011 - 12:39 PM, said:

now im getting this :o

The following SQL failed : SELECT * FROM players WHERE keywords LIKE '%Van persie%'
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\New folder\search.php on line 36

So logically, one would plug the above statement into mysql (either through your admin panel or at the command prompt) to verify that your sql statement does what you expect it to.

mysql it telling you why it's failing. I would recommend you start there.
Was This Post Helpful? 0
  • +
  • -

#7 afshandc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-December 11

Re: Warning: mysql_num_rows() expects parameter 1 to be resource,

Posted 29 December 2011 - 10:55 AM

yup i found the error using that code thanks a lot for that mate!!!!
finnalyyyy got it done :) :)
:bananaman:
:genius:
thanks again guys :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1