View Full Version : getting odd number in error message

08-05-2008, 01:15 PM
I swear I had this working then I changed something (dont know what) and now its broken and m not able to fix it.

//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)){
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_result= mysql_query($stock_onhand_qry) or die ("Unable to get number of stock on hand".mysql_error());
echo "<br/>";
echo 'the item quantities are';
{ $stocks[] = $stockquantity; }
echo "<br/>".$stocks[$i]['stock_onhand'] ;


the output of the code is

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.

08-05-2008, 02:32 PM
$stock_onhand_qry = "SELECT stock_onhand FROM stock WHERE item_id = $itemonhand[$i]"; Have a try by changing this to

$stock_onhand_qry = "SELECT stock_onhand FROM stock WHERE item_id = {$itemonhand[$i]}";

PS: You may simplify the code by the use of Join