Jump to content

Selecting identically named rows in two tables


BuildMyWeb

Recommended Posts

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'];
}

Link to comment
Share on other sites

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'];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.