...

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



qwertyjjj
11-04-2012, 08:12 PM
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.




//////////////////////////////////////////////

// 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
}
}
}

tangoforce
11-04-2012, 08:13 PM
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?

qwertyjjj
11-04-2012, 08:23 PM
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
?

qwertyjjj
11-04-2012, 08:26 PM
I see. got it thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum