Jump to content

HELP! mysql_num_rows() expects parameter 1 to be resource, boolean given...


mat3000000

Recommended Posts

The 2 errors I am getting are:

 

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\searchstock2.php on line 36

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\searchstock2.php on line 38

 

I am trying to search a table and return results, all fields are VARCHAR except ID (integer), here is part of my code;

 

 

$link = mysql_connect("localhxxxxx","xxx",""); //(host, username, password)


mysql_select_db("wadkin", $link) or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$query = "select * from stocklist where Stock Number like \'%$trimmed%\'OR Name like \'%$trimmed%\' OR Category like \'%$trimmed%\'"; 


if ($numresults=mysql_query($query));
	$row = mysql_fetch_assoc($numresults); 
    if ($row['COUNT(*)'] == 0);
$numrows=mysql_num_rows($numresults);


if ($numrows == 0)
  {
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>";
  }

// Determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: "" . $var . ""</p>";

// begin to show results set
echo "Results";
$count = 1 + $s ;

// display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row["Name"];

  echo "$count.) $title" ;
  $count++ ;
  }

 

$row = mysql_fetch_assoc($numresults);  = line 36

$numrows=mysql_num_rows($numresults); = line 38

 

Link to comment
Share on other sites

Actually, having another look at your code, it looks like you very much attempted to do so, you just have syntax errors.

 

if ($numresults=mysql_query($query)) { 
  if (mysql_num_rows($numresults)) {
    // successfullu use $numresults
  } else {
    // no results found
  }
} else {
  // query failed
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.