Jump to content

[SOLVED] question regarding a mysql query


jbrill

Recommended Posts

Hey guys,

i'm currently trying to code my own shopping cart and have run into a little snag, I'm hoping someone here can help me.

 

i have two tables in my database which i need to comunicate between. The tables are as follows:

 

products -  this stores the product information (productnumber, productname, price)

cartitems - this stores the things the user has added to cart.

 

basically, what i need to do is run a query that will search through the cartitems table and find the correct info from the products table.

 

so lets say in my cart items table i have a productid that is "1" i need to search the products table and find the item where the id="1" and display the productnumber and productname.

 

how would i go about doing this?

Link to comment
Share on other sites

thakn you very much this worked perfectly.

Now, i ahve one more question for you.

 

this is my query as it stands now:

$query  = "SELECT p.product_number, p.product_name FROM products p LEFT JOIN cartitems c ON c.productid = p.id WHERE userid = '" . $_SESSION['userid'] . "'";
$result = mysql_query($query) or die('Error, query failed');

// print the random numbers
while($row2 = mysql_fetch_array($result))
{
echo '<tr><td><input type="text" name="qty" value="' . $row2['qty'] .'" size="3"></td><td>'. $row2['product_number'] .'</td><td>'. $row2['product_name'] .'</td></tr>';
}

 

I am able to retreive the product_number and product_name from the products table, now i need to show the quantiry form the cart items table. this si seen in my code above <input type="text" name="qty" value="' . $row2['qty'] .'" size="3">

the qty is not showing, i guess becuse its looking in the products table and there is no such row in that table. how would i go about doing this?

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.