Adrien Posted October 9, 2015 Share Posted October 9, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/ Share on other sites More sharing options...
scootstah Posted October 9, 2015 Share Posted October 9, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522818 Share on other sites More sharing options...
Adrien Posted October 9, 2015 Author Share Posted October 9, 2015 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... Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522821 Share on other sites More sharing options...
Ch0cu3r Posted October 9, 2015 Share Posted October 9, 2015 (edited) 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 October 9, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522822 Share on other sites More sharing options...
Adrien Posted October 9, 2015 Author Share Posted October 9, 2015 ok I understand, If i want to add more information can I dot it ? href="productDetails.php?productId=<?php echo $donnees['Id','Id2','id3'] ?>" Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522823 Share on other sites More sharing options...
Ch0cu3r Posted October 9, 2015 Share Posted October 9, 2015 No. Not like that. To pass more than one value in the querystring you separate each key/value pair with an ampersand, eg filename.php?id=value2&id2=value2&id3=value3 Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522827 Share on other sites More sharing options...
cyberRobot Posted October 9, 2015 Share Posted October 9, 2015 The IDs could also be passed with a delimiter. For example: <?php if(isset($_GET['myIDs'])) { $_GET['myIDs'] = explode('|', $_GET['myIDs']); echo '<pre>' . print_r($_GET['myIDs'], true) . '</pre>'; } ?> <a href="?myIDs=1|3|4">Test</a> Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522828 Share on other sites More sharing options...
Adrien Posted October 9, 2015 Author Share Posted October 9, 2015 ok perfect ! thanks you all =) i'll continue to learn Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522830 Share on other sites More sharing options...
Jacques1 Posted October 9, 2015 Share Posted October 9, 2015 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.) 1 Quote Link to comment https://forums.phpfreaks.com/topic/298506-catalogue-product/#findComment-1522832 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.