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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.