deansaddigh Posted November 19, 2009 Share Posted November 19, 2009 On my homepage it displays products, i want to make another page that if they click on one of the products it takes em to a page witch shows the product details in its fullness. would i just pass the product id across the url? Quote Link to comment Share on other sites More sharing options...
Trizen Posted November 19, 2009 Share Posted November 19, 2009 need something more to work with, more info is needed Quote Link to comment Share on other sites More sharing options...
Bricktop Posted November 19, 2009 Share Posted November 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted November 19, 2009 Author Share Posted November 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted November 19, 2009 Author Share Posted November 19, 2009 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? Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted November 19, 2009 Author Share Posted November 19, 2009 I really need help with this can anyone provide a snippet of code, or anything so i can just get a start. <td><?php echo $productname;?></td> i want the product name to be clickable and then pass its ID to another page Quote Link to comment Share on other sites More sharing options...
Bricktop Posted November 19, 2009 Share Posted November 19, 2009 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. 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.