Jump to content

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

Edited by maxxd
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.