I have a site that currently works as far as filtering options, so when someone selects a serial number from a dropdown and hits submit, my display.php page comes up and fills multiple html tables with the database elements corresponding to that serial number.
My new task is to fill the display page the same way but the means of getting there are different. Currently, if you select from drop down and hit submit, I post the submit button to the display.php page and the display page pulls the request, like so:
if(isset($_POST['submit']))
{
$query1 = "SELECT *
FROM staging
WHERE stageID = ".$_REQUEST['serialNumber'].";";
This checks the serial number selected against the database and pulls the entire record that's attached to it.
Now I have an html table on the main page and it fills with all the records in the database table. I would like to make each 'row' an html link with href and when that link is selected it pulls the display.php page and fills the tables with that values. The tables on display.php are already echoing the rows with the correct values from the database table so I just need a new way of populating from the link.
I know there's a way to use href on the elements, but the table is filled from the SQL statement result, like so:
<div class="dashboardTable">
<table style="border: 1px solid black;">
<tr>
<th>Work Order Packet</th>
<th>Work Order Number</th>
<th>Date</th>
<th>Utility</th>
<th>Service Name</th>
<th>Address</th>
<th>Serial No.</th>
</tr>
<?php
while($row = mysqli_fetch_array($result1)){
?>
<tr>
<td><? echo $row['workOrderPacket'];?> </td>
<td><? echo $row['workOrderNum'];?> </td>
<td><? echo $row['date'];?> </td>
<td><? echo $row['utility'];?> </td>
<td><? echo $row['serviceName'];?> </td>
<td><? echo $row['address'];?> </td>
<td><? echo $row['serialNumber'];?> </td>
</tr>
<?}?>
</table>
</div>
So, when someone clicks a link, is there a way to bring up my display.php page and check the database for a record that satisfies those 7 elements? Or even if I need to copy my display.php tables into a new file so that it doesn't confuse with the dropdown $_REQUEST.
You can just add a regular link to the table, and alter you display page to allow either post or get:
<tr>
<th>Work Order Packet</th>
<th>Work Order Number</th>
<th>Date</th>
<th>Utility</th>
<th>Service Name</th>
<th>Address</th>
<th>Serial No.</th>
<th>View details</th>
</tr>
<?php
while($row = mysqli_fetch_array($result1)){
?>
<tr>
<td><? echo $row['workOrderPacket'];?> </td>
<td><? echo $row['workOrderNum'];?> </td>
<td><? echo $row['date'];?> </td>
<td><? echo $row['utility'];?> </td>
<td><? echo $row['serviceName'];?> </td>
<td><? echo $row['address'];?> </td>
<td><? echo $row['serialNumber'];?> </td>
<td><a href="/display.php?serialNumber=<? echo $row['serialNumber'];?>">view</a></td>
</tr>
<?}?>
display.php
//if(isset($_POST['submit']))
if(isset($_REQUEST['serialNumber']))
{
$query1 = "SELECT *
FROM staging
WHERE stageID = ".$_REQUEST['serialNumber'].";";
Also worth noting you are open to SQL injection, you should look into using prepared statements