BuildMyWeb Posted February 14, 2013 Share Posted February 14, 2013 the text in red is where im confused. how do i assign values for $orders_id and $shipping_id from their respective tables in one query? i imagine it can be done. i dont have to do 2 separate queries, do i? $query_order = "SELECT orders.id, shipping.id FROM orders, shipping WHERE orders.order_num = shipping.order_num AND orders.order_num = \"$order_req\""; $result_order = $db->query( $query_order ); $num_rows_order = $result_order->num_rows; for( $i=0; $i < $num_rows_order; $i++ ) { $row_order = $result_order->fetch_assoc(); // put field values for the row in an array $orders_id = $row_order['id']; $shipping_id = $row_order['id']; } Quote Link to comment Share on other sites More sharing options...
Barand Posted February 15, 2013 Share Posted February 15, 2013 select column aliases Select orders.Id as oid... Quote Link to comment Share on other sites More sharing options...
BuildMyWeb Posted February 15, 2013 Author Share Posted February 15, 2013 thanks Barand. so like this? $query_order = "SELECT orders.id AS oid, shipping.id AS sid FROM orders, shipping WHERE orders.order_num = shipping.order_num AND orders.order_num = \"$order_req\""; $result_order = $db->query( $query_order ); $num_rows_order = $result_order->num_rows; for( $i=0; $i < $num_rows_order; $i++ ) { $row_order = $result_order->fetch_assoc(); // put field values for the row in an array $orders_id = $row_order['oid']; $shipping_id = $row_order['sid']; } Quote Link to comment Share on other sites More sharing options...
Barand Posted February 15, 2013 Share Posted February 15, 2013 Yes, and no Aliases are right. If you are only expecting a single row then you don't want a for loop. If you expect several rows the ids will be overwritten in each loop and you will only get the last ones Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.