phpjordan Posted November 10, 2016 Share Posted November 10, 2016 Hi All, this is my first post on here so please go easy! I am creating a portal type application, I have a page that has a table on with a list of customers in, but I want to link the customer name to a new page that gives me a list of that customers products, I have it working where I am setting the customer ID in the SQL WHERE clause but I want to do this dynamically so when a user clicks on customer 1 its customer 1's products that are loaded etc. Here is the first table: SQL: $customerList = "SELECT T0.CardCode, T0.CardName FROM OCRD T0 WHERE T0.SlpCode = 947"; $myCustomers = sqlsrv_query( $sapconn, $customerList); HTML/PHP: <table> <thead> <tr> <th>SLP Code</th> <th>SLP Name</th> </tr> </thead> <tbody> <?php while($customer = sqlsrv_fetch_array($myCustomers, SQLSRV_FETCH_ASSOC)) : ?> <tr> <td> <a href="specialprice.php"> <?php echo $customer['CardName'];?> </a> </td> <td><?php echo $customer['CardCode'];?></td> </tr> <?php endwhile; ?> </tbody> </table> Then it Links to this page (specialprice.php) to show the relevant products: SQL: $specialPricing = "SELECT T0.ItemCode, T0.ItemName, CAST(T1.Price AS DECIMAL(9,2)) AS Price FROM oitm T0 JOIN ospp T1 ON T0.ItemCode = T1.ItemCode WHERE T1.CardCode = 'CM000001-M'"; $oitmTable = sqlsrv_query( $sapconn, $specialPricing); PHP: <table> <thead> <tr> <th>SLP Code</th> <th>SLP Name</th> <th>Price</th> </tr> </thead> <tbody> <?php while($users1 = sqlsrv_fetch_array($oitmTable, SQLSRV_FETCH_ASSOC)) : ?> <tr> <td><?php echo $users1['ItemCode'];?></td> <td><?php echo $users1['ItemName'];?></td> <td>£<?php echo $users1['Price'];?></td> </tr> <?php endwhile; ?> </tbody> </table> But i want it where the id of "CM000001-M" is dynamic to which customer has been clicked. Any advice on how to achieve this? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/302508-passing-variables-through-links/ Share on other sites More sharing options...
requinix Posted November 10, 2016 Share Posted November 10, 2016 Use the query string: construct your URLs to look like specialprice.php?cardcode=CM000001-Mby doing In specialprice.php you can access the value with $_GET['cardcode']. But don't put it directly into your SQL because anyone could put whatever they wanted into the URL for the "cardcode" and mess up your SQL, your data, and your entire database if they wanted. Instead use prepared statements in place of sqlsrv_query. Quote Link to comment https://forums.phpfreaks.com/topic/302508-passing-variables-through-links/#findComment-1539195 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.