Jump to content

JOIN 2 tables to compare values


matthew798

Recommended Posts

Hi guys! Once again i require your endless talents!

 

I have 2 tables in my mysql DB. One table is a list of products a store offers, the other is the cart of the user. I need to find the most efficient way or retrieving the images and prices from the LIST OF PRODUCTS table based on the list of PRODUCT NUMBERS stored in the cart table of the user.

 

List of products offered

 

*************************

Prod # * Price *      img src    *

*************************

001    * 19.99* imgs/pic1.jpg *

002    * 29.99 * imgs/pic2.jpg *

*************************

 

User's Cart

*********************

Prod # * quantity * size *

*********************

001    *    10      *  m    *

002    *    4        *  s    *

********************

 

Basically i just want to retrieve ONLY the rows that i need (ones that the user has added to his/her cart) and ASSOCIATE the img src with the quantity and size so that i can lay it out in a table on a view_cart page...

 

If you want a good laugh just take a look at what ive done so far...

 

$cart = mysql_query("SELECT * FROM ".$session."");

$cart_row_count = mysql_fetch_assoc($cart);
$cart_row_count = mysql_num_rows($cart_row_count);

if($cart_row_count != 0){

$i = 1;

while($cart_result = mysql_fetch_assoc($cart)){
	${"product$i"} = $cart_result['product'];
	${"size$i"} = $cart_result['size'];
	$i++;
}

$i2 = 1;

$query = "product = ".${"$product$i2"}." ";

while($i2 <= $i){
	$i2++;
	$query .= "AND ".${"$product$i2"}." ";
}
}

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.