Alex Alex - 11 months ago 34
MySQL Question

Mysql/Php - Displaying the single product page selected from a list

I have a PHP page that's the product list as depicted below. The last column is the link to the single product page reporting all the details about that product.

ID | Title | LINKTOPAGE
-------|--------------|------------------
001 | ProductTitle | $ID(001)-->Link to the single_product_page.php
002 | ProductTitle | $ID(002)-->Link to the single_product_page.php
003 | ProductTitle | $ID(003)-->Link to the single_product_page.php


The above table is generated by the following loop:

<?php
while ($row = mysqli_fetch_array($risultato)){
echo '<tr>
<td>'.$row['id'].'</td>
<td>'.$row['post_title'].'</td>
<td>'.'LinkToSinglePage >>'.'</td>
</tr>';
}?>


I have already prepared the single page that retrieves data from this query:

SELECT
p.id as ID,
p.post_title,
p.post_status,
p.post_excerpt as shortdesc,
p.post_content as longdesc
FROM mg_posts as p
WHERE p.ID= 13323
GROUP BY p.ID


What I am trying to do it is to link the "linktoProductPaGe" to the single page. If I am not wrong I should replace the ID=13323 with the variable that stores the ID of the selected product in the list.

Any suggestion on how?

Answer Source

You can do it like that, for example (get method):

Product list (products_lists.php):

 <?php
      while ($row = mysqli_fetch_array($risultato)){
           echo '<tr>
                     <td>'.$row['id'].'</td>
                     <td>'.$row['post_title'].'</td>
                     <td>single_product_page.php?product_id='.$row['id'].'</td> 
                </tr>';
      }?>

And in your product detail page (single_product_page.php), you can get the id like that:

<?php $product_id = $_GET['product_id']; ?>

Hope that will help. :-)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download