Jump to content

[SOLVED] Simple i think.


deansaddigh

Recommended Posts

Hi deansaddigh,

 

Yes, basically, pass the ID via the URL, then on the page which displays the product in its entirety have a MySQL query which querires the database for the product WHERE id = $_GET['id'] (for example)

 

Obviously the above is a very very basic example, in the real world you would need to sanitize the $_GET data before inserting into a query.

 

Hope this helps.

Oh ok sorry for my vague , description.

 

Basically if you look at this site, which i am trying to mimic for practice etc.

 

http://mailordercorals.com/?SID=19b13942b5ec0ae822ccc4c6cb17da4eebay-coral-auctions

 

If you look on there front page they have some corals, if you click on the first coral the neon green candy cane, it takes you to the product details for that product, this is what i want to do, i just need to know how they do it or what they are doing, so i can figure out the code

Ok one thing i dont understand is obviously my code is looping through my products in order to display each product, how do i pass the id across depending on which product has been selected.

 

here is the code when i echo out product details.

 

<td><?php echo $productname;?></td>
					<td><?php echo $row['ProductCategory'];?></td>
					<td><?php echo $row['ProductPrice'];?></td>
					<td><?php echo $row['ProductDescription'];?></td>
                        <?php echo '<td><a href="'.$file.'" target="_blank" rel="lightbox"><img src="'.$file.'" width="100" height="100"/></td>';?>

 

how would i make say the product name clickable and then pass through the product id?

Hi deansaddigh,

 

Firstly, create a page called "productdetail.php", this will be the page which displays the details of each product.

 

Now, change the line of code which you would like clickable to be:

 

<td><?php echo '<a href="productdetail.php?product='.$row['id'].'">'.$productname.'</a>';?></td>

 

(Assuming the ID field is called 'id' in the database, change it accordingly if not)

 

Now, on your productdetail.php page, insert the following function, this will cleanse the $_GET data and make it safe to insert into a query.

 

function make_safe($unsafe)
{
//This needs to be the database connection file
             require("connect.php");
$safe = mysql_real_escape_string(strip_tags(trim($unsafe)));
return $safe;
}

 

Now, have a query on your productdetail.php file which reads something like:

 

$sql = mysql_query("SELECT * FROM yourtable WHERE id = '".make_safe($_GET['product'])."' ORDER BY id DESC");

 

Obviously, you haven't given much to work on but the above should help you build the page to your requirements.

 

Hope this helps.

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.