Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2012, 03:57 PM   PM User | #1
qwertyjjj
New Coder

 
Join Date: Dec 2007
Posts: 59
Thanks: 1
Thanked 0 Times in 0 Posts
qwertyjjj is an unknown quantity at this point
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>";
	
?>
qwertyjjj is offline   Reply With Quote
Old 11-04-2012, 11:44 PM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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)?
Inigoesdr is offline   Reply With Quote
Old 11-05-2012, 07:51 AM   PM User | #3
qwertyjjj
New Coder

 
Join Date: Dec 2007
Posts: 59
Thanks: 1
Thanked 0 Times in 0 Posts
qwertyjjj is an unknown quantity at this point
Quote:
Originally Posted by Inigoesdr View Post
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?

Last edited by qwertyjjj; 11-05-2012 at 07:57 AM..
qwertyjjj is offline   Reply With Quote
Old 11-05-2012, 08:06 AM   PM User | #4
qwertyjjj
New Coder

 
Join Date: Dec 2007
Posts: 59
Thanks: 1
Thanked 0 Times in 0 Posts
qwertyjjj is an unknown quantity at this point
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.
qwertyjjj is offline   Reply With Quote
Old 11-05-2012, 01:39 PM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,505
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:06 AM.


Advertisement
Log in to turn off these ads.