Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts

    mysql_num_rows(): supplied argument is not a valid MySQL result resource

    I get a
    mysql_num_rows(): supplied argument is not a valid MySQL result resource
    error on the bold line.
    Can't figure out why and can't see any error in the SQL.

    Code:
    //////////////////////////////////////////////
    
    // FIND ANY ORDERS THAT WERE MARKED AS DELIVERED
    // BUT HAVE NOT BEEN MADE ACTIVE IN SQUID OR OPENVPN TABLES
    
    //////////////////////////////////////////////
    
    $db_selected = mysql_select_db("AAAAA", $squid_conn_int);
    if (!$db_selected) {
        mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
        die ('Can\'t use database: ' . mysql_error());
    }
    
    $result = mysql_query("
    
    SELECT orders.orders_id , orders.customers_id , orders.customers_name , orders.customers_email_address , orders.payment_method , orders.last_modified , 
    orders.orders_status , orders_products.products_id, products_description.products_name
    FROM orders
    INNER JOIN orders_products ON orders_products.orders_id = orders.orders_id
    INNER JOIN products_description ON products_description.products_id = orders_products.products_id
    WHERE orders_status =3
    AND last_modified > NOW( ) - INTERVAL 120 MINUTE
    ORDER BY orders_id DESC" , $squid_conn_int
    );
    
    if (mysql_num_rows($result) > 0) {
    while ($box = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
    		//if found, take order ID and products id
    		$oid = $box['orders.orders_id'];
    		$custid = $box['orders.customers_id'];
    		$prodid = $box['orders_products.products_id'];
    
       	//if proxy, check if active in squid
    		mysql_select_db("squid", $squid_conn_remote);
    		if (!$db_selected) {
    	   					mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
    	   					die ('Can\'t use database: ' . mysql_error());
    	   }
    		if  ($prodid == 31 || 
    				$prodid == 28 || 
    				$prodid == 29 || 
    				$prodid == 34 || 
    				$prodid == 40 ||
    				$prodid == 32)
    		{					
    					$newresult = mysql_query('SELECT customers_id FROM passwd WHERE customers_id = '.$custid.' AND enabled = 0 AND UpdateOnNextCycle = 0', $squid_conn_remote)
    					             or die (mysql_error());
    		}
          mysql_select_db("squid", $squid_conn_remote);			
    		if  ($prodid == 37 || 
    				$prodid == 38 )
    		{					
    				
    					$newresult = mysql_query('SELECT customers_id FROM OpenVPN WHERE customers_id = '.$custid.' AND enabled = 0 AND UpdateOnNextCycle = 0', $squid_conn_remote)
    					             or die (mysql_error());
    		}
    		if (mysql_num_rows($newresult) == 0) {
    				//if not active in squid or VPN then connect to OSC database
    				//delete anything in orders status history with 1
          		//change status in orders to 1
          		$db_selected = mysql_select_db("AAAAA", $squid_conn_int);
    				if (!$db_selected) {
    	    							mail('AAAAA@AAAAA.co.uk', 'IntegrityCheck script error', mysql_error().' error');
    	    							die ('Can\'t use database: ' . mysql_error());
    				}
    				mysql_query("DELETE FROM orders_status_history WHERE orders_id = ".$oid." AND customer_notified = 1", $squid_conn_int)
    				  or die (mysql_error());
    				mysql_query("UPDATE orders SET orders_status = 1 WHERE orders_id = ".$oid, $squid_conn_int)
    				  or die (mysql_error());
    							
    				//these orders will now be picked up by the next IntegrityCheck run in the top part of this script
    		}
    }
    }

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,439
    Thanks
    62
    Thanked 537 Times in 524 Posts
    What I notice you are doing is checking for a number of rows even if you do not run a query (because the query is inside an if clause). IF you do not run a query then there will be no result to pass into mysql_num_rows() and it will generate this error.

    The only way to stop this is not to use mysql_num_rows() if you do not run the query. Why not move it inside the if clause under the query?
    Last edited by tangoforce; 11-04-2012 at 08:16 PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    qwertyjjj (11-04-2012)

  • #3
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    What I notice you are doing is checking for a number of rows even if you do not run a query (because the query is inside an if clause). IF you do not run a query then there will be no result to pass into mysql_num_rows() and it will generate this error.

    The only way to stop this is not to use mysql_num_rows() if you do not run the query. Why not move it inside the if clause under the query?
    I'm a bit lost on where you mean.
    There are 2 different database connections here and the query shouldn;t run unless it passes the if test
    ?

  • #4
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I see. got it thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •