jbrill Posted November 15, 2007 Share Posted November 15, 2007 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? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 15, 2007 Share Posted November 15, 2007 Give this query a try. SELECT p.productnumber, p.productname FROM products p LEFT JOIN cartitems c ON c.productid = p.productid Quote Link to comment Share on other sites More sharing options...
jbrill Posted November 15, 2007 Author Share Posted November 15, 2007 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? Quote Link to comment Share on other sites More sharing options...
jbrill Posted November 15, 2007 Author Share Posted November 15, 2007 nevermind, im an idiot. figured it out lol 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.