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 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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>";
    	
    ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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)?

  • #3
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    Dec 2007
    Posts
    65
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,325
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    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.
    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!


  •  

    Posting Permissions

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