Hi all, greetings from Portugal.

I know, there is a "Supplied argument not valid resource" FAQ, and I know there are allready a few threads about this, but after reading them and hours of changing code I still have my problem...
(Yes, I'm a newbie :-) )

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9144269/public_html/ebiznet/toDataGridTest2.php on line 68
&errorcode=3&msg=&

Here is my code (I'm a code tag virgin, so I hope I'm doing it right...):

<?
/*
   errorcode:
      0: successful select
      1: can't connect to server
      2: can't connect to database
      3: can't run query
*/

$server = "...";
$username = "...";
$password = "...";
$database = "...";
$table= "...";


$part1 = $_POST["var1"];
$part2 = $_POST["var2"];
$part3 = $_POST["var3"];
$part4 = $_POST["var4"];
$part5 = $_POST["var5"];
$part6 = $_POST["var6"];
$part7 = $_POST["var7"];

if($part1==0) $p1="dp01 IS NOT NULL";
	else
	$p1="dp01 = ".$part1;

if($part2==0) $p2="dp02 IS NOT NULL";
	else
	$p2="dp02 IS NOT NULL";

if($part3==0) $p3="dp03 IS NOT NULL";
	else
	$p3="dp03 <= ".$part3;

if($part4==0) $p4="dp04 IS NOT NULL";
	else
	$p4="dp04 >= ".$part4;

if($part5==0) $p5="dp05 IS NOT NULL";
	else
	$p5="dp05 <= ".$part5;

if($part6==0) $p6="dp06 IS NOT NULL";
	else
	$p6="dp06 = ".$part6;

if($part7==0) $p7="dp07 IS NOT NULL";
	else
	$p7="dp07 = ".$part7;
 
if (!mysql_connect($server, $username, $password)) {
   $r_string = '&errorcode=1&';	

} elseif (!mysql_select_db($database)) {
   $r_string = '&errorcode=2&';
	
} else {
	
	
	$qr='SELECT * FROM  $table WHERE ' . $p1 . ' AND ' . $p2 . ' AND ' . $p3 . ' AND ' . $p4 . ' AND ' . $p5 . ' AND ' . $p6 . ' AND ' . $p7;

   if (!qr || mysql_num_rows($qr)==0) {
      $r_string = '&errorcode=3&msg='.mysql_error().'&';
   } else {
      $r_string = '&errorcode=0&n='.mysql_num_rows ($qr);
      $i = 0;
      while ($row = mysql_fetch_assoc ($qr)) {
         while (list ($key, $val) = each ($row)) {
            $r_string .= '&' . $key . $i . '=' . stripslashes($val);
         }
         $i++;
      }
      // add extra & to prevent returning extra chars at the end
      $r_string .='&';
   }
}
echo $r_string;
?>

my line 68 is:

if (!qr || mysql_num_rows($qr)==0) {

ok, my query is a bit strange... but I tested it with:

$qr='SELECT * FROM $table';

and still the same error.


Can someone help me?
thanks!

Should there be a $ in front of the first qr on line 68?

Hi slyme,

!qr

is quit right I think...

But i found my error:

Too much hours without coffy :-)

$qr='SELECT * FROM ebnetTest WHERE ' . $p1 . ' AND ' . $p2 . ' AND ' . $p3 . ' AND ' . $p4 . ' AND ' . $p5 . ' AND ' . $p6 . ' AND ' . $p7;

should be of course:

$qr=mysql_query('SELECT * FROM ebnetTest WHERE ' . $p1 . ' AND ' . $p2 . ' AND ' . $p3 . ' AND ' . $p4 . ' AND ' . $p5 . ' AND ' . $p6 . ' AND ' . $p7)or die(mysql_error());

stupid me :-)

Of course! Too many hours without nicotine here!

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.