CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   cannot use mysql_fetch_array no error (http://www.codingforums.com/showthread.php?t=280833)

qwertyjjj 11-04-2012 03:57 PM

cannot use mysql_fetch_array no error
 
I am trying to echo out the resultset but I just get the text error:
"Can't use resultset" from the die command (in bold below)
Any ideas what could be wrong?

Code:

<?php

/////////////////////////////////////////////////////////
//1. INTEGRITY CHECK SCRIPT IN CASE OF LOST CONNECTIONS
////////////////////////////////////////////////////////

//conn 1
$squid_conn_int = mysql_connect("mysqlxxxx.xxxxxxx.com",
                            "user",
                            "pw");
        if (!$squid_conn_int)
          {
                  mail('aaaa@aaaaa.com', 'IntegrityCheck script error', mysql_error().' error');
                  die('Could not connect: ' . mysql_error());
          }

//EXISTING PENDING ORDERS
//-------------------------
//check for paypal hack where order is confirmed ok but no validation

$db_selected = mysql_select_db("user", $squid_conn_int) or die ('Can\'t use database: ' . mysql_error());

$query = "
SELECT o.orders_id, o.orders_status, osh.comments
FROM orders o
INNER JOIN orders_status_history osh ON osh.orders_id = o.orders_id
AND osh.orders_status_id =1
AND o.orders_status =3
ORDER BY o.orders_id DESC ";

$result = mysql_query($query) or die(mysql_error());
echo "<table>";

while ($squid = mysql_fetch_array($result, MYSQL_ASSOC)
                                or die ('Can\'t use resultset: ' . mysql_error())
) {

        $oid = $squid['o.orders_id'];
        $ocomments = $squid['osh.comments'];
        echo "<tr>";
        echo "<td>".$squid['o.orders_id']."</td><td>".$squid['o.orders_status']."</td><td>".$squid['osh.comments']."</td>";
        echo "</tr>";



}
echo "</table>";
       
?>


Inigoesdr 11-04-2012 11:44 PM

Are you sure there isn't an error after the "Can't use resultset" text? Does your query return results when you run it directly (phpMyAdmin, HeidiSQL, etc)?

qwertyjjj 11-05-2012 07:51 AM

Quote:

Originally Posted by Inigoesdr (Post 1288562)
Are you sure there isn't an error after the "Can't use resultset" text? Does your query return results when you run it directly (phpMyAdmin, HeidiSQL, etc)?

No error afterwards unless it's just not reporting SQL errors.
The SQL runs find in phpmyadmin

the page source prints this, which doesn't make any sense because it is supposed to have exited when it hit the die command

Code:


<table><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr>Can't use resultset:

and can I use the column name osh.comments in the code or do I have to use just comments?

qwertyjjj 11-05-2012 08:06 AM

Fixed it.
I took out the die command from the while section as it can't go there.
Also, I renamed the columns to use an AS name as it cannot pick up rows with ambiguous column names.

tangoforce 11-05-2012 01:39 PM

or die() can only be used where you could test for a boolean but haven't used an if ().

In your case, $result = mysql_query($query) or die(mysql_error()); would return either false or a non false result so or die() will work correctly.

while () does not return a result. Therefore using or die() could never work properly there.


All times are GMT +1. The time now is 03:47 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.