Jump to content

Calling One Table Cell from sql database


Dorkmind

Recommended Posts

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.

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().

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.