mysql - Sending a PHP variable to another page via click on anchor tag -
this simplified version of files working with:
on product-list.php have like:
<ul> <li><a href="prouduct-detail.php">product1</a></li> <li><a href="prouduct-detail.php">product2</a></li> <li><a href="prouduct-detail.php">product3</a></li> </ul>
on product-detail.php want use like:
include_once("db_config.php"); $product_detail_query = 'select * prod_details product_name = ???';
when clicks on product in product-list.php want text between anchor tags sent product-detail.php , beplaced in sql query @ product_name = (where have ???) can access specific row , lay out details.
what best way achieve this?
product list.php
<a href="product-detail.php?product_id=1">product</a>
on product-detail.php
$product_id = (int)$_get['product_id'];
then, bind $product_id db query.
you can replace urlencoded product name, should stick unique identifiers this.
foreach ($products $product) { echo '<a href="product-detail.php?id=' . $product['id'] . '">' . $product['name'] . '</a>'; }
Comments
Post a Comment