Jump to content

Passing variables through links?


phpjordan

Recommended Posts

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.

 

Link to comment
Share on other sites

Use the query string: construct your URLs to look like

specialprice.php?cardcode=CM000001-M
by 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.
Link to comment
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.