Jump to content


*SOLVED* annoying problem

  • Please log in to reply
2 replies to this topic

#1 corvyr

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 02 April 2006 - 11:50 PM

I get this message only on the page when I haven't done a search with it

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/aaronkor/public_html/beastpage.php on line 4

The error in question is on an included php file and as I said only appears until I use the search feature on the page. Below is a bit of the code where the error is happening

$query = "SELECT count(*) as count FROM stats WHERE ".$_GET['mode']." LIKE '%$searchstring%'"; 
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$numrows = $row['count'];

Any help would be appreciated.

#2 toplay

  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 03 April 2006 - 12:24 AM

You should check for any possible MySQL errors before executing any subsequent MySQL related commands. You're getting that because there's an SQL syntax error on the query and you went ahead and still executed the fetch, which is wrong. Notice that "count" is a reserved word (for a function) in MySQL and you're "AS" is named the same. Change it to something else (recommended) or enclosed it in backtick marks.

$query = "SELECT count(*) as `count` FROM stats WHERE {$_GET['mode']} LIKE '%$searchstring%'";
$result = mysql_query($query) or die('SQL: ' . $query . ' Error: ' . mysql_error());
$row = mysql_fetch_array($result);
if (!$row) {
    echo 'No data';
} else {
    $numrows = $row['count'];
    echo 'Count: ', $numrows;

FYI for all: This error is described in the FAQ page pinned at the top of the newbie topic area.

#3 corvyr

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 03 April 2006 - 12:45 AM

Fixed it just before I noticed the reply, had the include() in the wrong spot it seems.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users