Dorkmind Posted November 24, 2014 Share Posted November 24, 2014 Hi guys i have another question about my shopping cart. I have in my sql database table called products. It consist of 4 columns (product_id, description, quantity, price). Now on my index page, I want to call just one product from cell, which would have special price. But i don't know how to call one single product. So my code looks like that: <?php $sql="SELECT product_id FROM Products"; $query=mysql_query($sql); $row=mysql_fetch_array($query); ?><table > <tr><img src="Images/Image.jpg" width="380" height="300" /> </tr> <tr> <td><a href="index.php?page=index&action=add&id=<?php echo $row['product_id']?>">Add to cart</a></td> </tr> <?php ?> </table> This code display me first product but i would like to call 3 product how would i do that, so i have 6 products and i would like to call product N.3 to my index page. My code calls the first one, how would it call the third. Quote Link to comment https://forums.phpfreaks.com/topic/292676-calling-one-table-cell-from-sql-database/ Share on other sites More sharing options...
maxxd Posted November 24, 2014 Share Posted November 24, 2014 (edited) Change your query to this: $sql = "SELECT description ,price ,quantity FROM Products WHERE product_id = 3"; Of course, if you're trying to get a dynamic product you'll have to pass the product_id in to the query (usually pulling the value from $_GET) so don't forget you're going to have to sanitize any user input. Also, the mysql_* functions have been deprecated for quite some time now - look into PDO() or mysqli(). Edited November 24, 2014 by maxxd Quote Link to comment https://forums.phpfreaks.com/topic/292676-calling-one-table-cell-from-sql-database/#findComment-1497487 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.