Jump to content

Recommended Posts

Hi all,

 

I create a catalogue page. I'made a few products displayed on it. but I want to create a link from the products to have more details of it.

product1 - product2 ... if I clic on product 1 I can show (in a lightbox) the details of it.

on this moment I do that but don't know how can i create the link for the product.

I think need a _post and a _get but not really how do this.

 

If anyone can help me... =)

$reponse = $bdd->query('SELECT * FROM MYDB LIMIT 200');while ($donnees = $reponse->fetch())
{
?>
<a href="<?php echo $url ?>">
<div class="divGeneral">
<img src='<?php echo $donnees['Image']; ?>' class="imgG" />
<?php
echo '<p> ' . $donnees['Titre'] . $donnees['Edition'] . '</p>';
?>
</div>
</a>
<?php
Link to comment
https://forums.phpfreaks.com/topic/298506-catalogue-product/
Share on other sites

You would use a querystring parameter to pass the ID of a product to your "details" page. Something like: productDetails.php?productId=123

 

Then, on the productDetails.php page, you just look for $_GET['productId'] and select that product from the database.

 

Make sure you properly escape the $_GET value before you use it in the database.

Link to comment
https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522818
Share on other sites

Thanks for your reply Scootstah,

 

on this moment my problem is not the productDetails.php page but the global catalog page.

 

I need to create a link on each products who you see on the page to go to the product details. 

with a form it's method=post but here I don't know really how can I do it.

 

exemple :

<a href="<?php productDetails.php?productId" ?> method=POST">
echo '<p> ' . $donnees['Titre'] . '-' . $donnees['Edition'] . '</p>';
</a>

I miss something but don't know what...

Link to comment
https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522821
Share on other sites

There is no method="post" for an anchor tag (<a></a>). 

 

href="<?php productDetails.php?productId" ?>  

 

needs to be (assuming your product id column is named Id)

 

 href="productDetails.php?productId=<?php echo $donnees['Id'] ?>"

Edited by Ch0cu3r
Link to comment
https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522822
Share on other sites

You actually can assign multiple values to a single parameter, but PHP wants you to mark this parameter with square brackets:

<?php

function html_escape($value, $encoding)
{
    return htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, $encoding);
}

if (isset($_GET['x']))
{
    echo 'The following values have been passed to the parameter x:<br>';
    foreach ($_GET['x'] as $x)
    {
        echo html_escape($x, 'UTF-8').'<br>';
    }
}

?>
<a href="test.php?x[]=1&x[]=2&x[]=3">Click me</a>

(The brackets should be URL-encoded as %5B and %5D, since they're reserved characters. This is only a demo.)

  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522832
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.