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

    getting odd number in error message

    I swear I had this working then I changed something (dont know what) and now its broken and m not able to fix it.

    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());
          
          
    //note the way this is done to get data from 2dimensional user defined array        
            
    while($orderitems mysql_fetch_array($order_result)){
        
    $itemids[]=$orderitems;
        }
            for(
    $i=0;$i<count($itemids);$i++)
        echo 
    "<br/>".$itemids[$i]['item_id'] ;

        
    //Now that we have id numbers we need to get quantity onhand from the stock table
        
    foreach($itemids as $i =>$itemonhand)
            {
        
    $stock_onhand_qry "SELECT stock_onhand FROM stock WHERE item_id = $itemonhand[$i]";
        
    $stock_resultmysql_query($stock_onhand_qry) or die ("Unable to get number of stock on hand".mysql_error());
            echo 
    "<br/>";
                    echo 
    'the item quantities are';
                    
    print_r($itemonhand);
            while(
    $stockquantity=mysql_fetch_array($stock_result))    
                    { 
    $stocks[] = $stockquantity; }    
                         for(
    $i=0;$i<count($stocks);$i++)
                                   echo 
    "<br/>".$stocks[$i]['stock_onhand'] ;
                }
                
               
        } 
    the output of the code is

    19
    25
    the item quantities areArray ( [0] => 19 [item_id] => 19 )
    10Unable to get number of stock on handYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    notice the 10 in front of unable to get number of stock. The ten has nothing to do with any user input and i have no idea where it could be coming from. I already know where the next hangup comes into play because earlier i was farther than this but thats a whole different post. Any help would be appreciated this is an ambitious project for me being as this is the first program i've written in any language but with some help from the people on this site ive sure learned a lot and made a lot of progress so thanks again to everyone who has helped

    ok i just realized that the 10 it the number of items stored in the DB so it is getting the first record and then failing an further attempts to retrieve records. I do need to get them all so help would still be great thanks.
    Last edited by irenaught; 08-05-2008 at 12:17 PM. Reason: had a thought

  • #2
    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
    $stock_onhand_qry = "SELECT stock_onhand FROM stock WHERE item_id = $itemonhand[$i]";
    Have a try by changing this to
    PHP Code:
    $stock_onhand_qry "SELECT stock_onhand FROM stock WHERE item_id = {$itemonhand[$i]}"
    PS: You may simplify the code by the use of Join
    Last edited by abduraooft; 08-05-2008 at 01:36 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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