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 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts

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

    Please help me... Here is the first part of the offending code.
    PHP Code:
    if (isset($_REQUEST['complete']))  {
        
    $order_complete_qry "UPDATE orders SET order_status = '2' WHERE order_id =$oid[order_id]";
        
    $result mysql_query($order_complete_qry)or die ("Cannot complete order: ".mysql_error()); 
    this works fine and updates the DB appropriately the following code immediately follows in the script as well

    PHP Code:
    //series of queries to update stock
        //this query should get all stock items added to order by user
        
    $current_order_qry "SELECT item_id FROM orderitems WHERE order_id= $oid[order_id] ORDER BY item_id";
        
    $order_result "mysql_query($current_order_qry) or die (\"Cannot get items on order: \".mysql_error())";
                  
            while(
    $orderitems mysql_fetch_array($order_result)){
        
    $itemids[]=$orderitems;
        } 
    this on gets a "mysql_fetch_array(): supplied argument is not a valid MySQL result resource in..." error. The update statement is designed to only pull one record and the select should draw multiples. I think therein lies the problem but im obviously not sure. Please help a pathetic newbie. If there is not enough code here let me know and I can post more I just didn't want to write a book for people to have to read.
    Last edited by irenaught; 08-03-2008 at 03:43 AM.

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    You're putting the whole command in quotes so it's a string - that's really not what you want.

    This:
    PHP Code:
    //series of queries to update stock
        //this query should get all stock items added to order by user
        
    $current_order_qry "SELECT item_id FROM orderitems WHERE order_id= $oid[order_id] ORDER BY item_id";
        
    $order_result "mysql_query($current_order_qry) or die (\"Cannot get items on order: \".mysql_error())";
                  
            while(
    $orderitems mysql_fetch_array($order_result)){
        
    $itemids[]=$orderitems;
        } 
    Should be this:
    PHP Code:
    //series of queries to update stock
        //this query should get all stock items added to order by user
        
    $current_order_qry "SELECT item_id FROM orderitems WHERE order_id= $oid[order_id] ORDER BY item_id";
        
    $order_result mysql_query($current_order_qry) or die ("Cannot get items on order: ".mysql_error());
                  
            while(
    $orderitems mysql_fetch_array($order_result)){
        
    $itemids[]=$orderitems;
        } 
    You should consider using a syntax highlighting editor - these simple errors tend to stick out better.
    Last edited by derzok; 08-03-2008 at 03:23 AM.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    please, put your code between [ php] and [ /php] or [ code] and [ /code] tags. You can edit your posts, thank you.

    try this:
    PHP Code:
    //series of queries to update stock
    //this query should get all stock items added to order by user
        
    $current_order_qry "SELECT item_id FROM orderitems WHERE order_id= $oid[order_id] ORDER BY item_id";
        
    $order_result mysql_query($current_order_qry) or die ("Cannot get items on order: ".mysql_error());
                  if(
    $order_result){
            while(
    $orderitems mysql_fetch_array($order_result)){
        
    $itemids[]=$orderitems;
        }
    }else{
    print 
    mysql_error();

    regards

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I just noticed the thing about the php tags but thanks for letting me know and thanks for the help as well.

  • #5
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok we are much closer now thank you but i still have one problem...
    PHP Code:
    echo "The items on the order are".".$itemids."."";

    printf("The items on the order are  : %s "$itemids[item_id]); 
    the first line outputs array and the second one nothing at all. Is it possible to echo the items like this or does it have to be a print_r statement instead?

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    echo "The items on the order are".$itemids['item_id']; 
    regards

  • #7
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you for your help. I always want to use the "thank user for this helpful post" but then it says to make sure that a lot of thought and effort went into the post I dont feel like it took a lot of effort for you to answer my easy question but I still really appreciate it so what is the standard etiquette? Thanks one way or the other.

  • #8
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I copied and pasted your code and i still get "The items on the order are" without the quotes and then nothing. If i print-r it i do get what im looking for but i need to display it to a user and then interact with sql based on the item id's it contains. I know its getting the right data so where do i go next?

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Code:
    while($orderitems = mysql_fetch_array($order_result)){
        $itemids[]=$orderitems;
    Code:
    echo "The items on the order are".$itemids['item_id'];
    Just have a look in to the output of print_r($itemids) statement
    It'd be starting with something like
    Code:
    Array ( [0] => Array ( [0]......) [1] =>
    From your code, it's clear that the array $itemids is going to be an array of array(2D), since $orderitems itself is an array(return value of mysql_fetch_array)
    Thus
    PHP Code:
    echo "The items on the order are";
    for(
    $i=0;$i<count($itemids);$i++)
        echo 
    "<br/>".$itemids[$i]['item_id'] ; 
    should give you some result.
    Last edited by abduraooft; 08-04-2008 at 10:22 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #10
    New Coder
    Join Date
    Jul 2008
    Posts
    19
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I added the code but still no effect. You are definately right about it being an array of arrays and I feel this is the problem but the code you offered had no output still. The print_r statement outputs as you expect it would. Do i need to use some kind of explode() or implode() type line or maybe a foreach instead of for statement? Ive been trying different code bits for going on two days. Please if you have any other suggestions please throw them out there and thanks for the help so far.


  •  

    Posting Permissions

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