0

I need help passing a value from a database. I've done this successfully with drop down boxes, and getting the selection then posting with a submit button where it would fill the tables in Display.php successfully. However, I'm now using an html table that fills with values as a list and uses the serial number as a hyperlink.

When the user selects the link and it opens Display.php, I want to grab the serial number associated with that link/row and use it in the SQL query on the display.php page so it can match that serial number with a stageID in my staging table and select all values for that row.

In the following code, if I debug the $_GET array, it shows the correctly chosen serial number. If I debug/print $_GET and $result1, I get:

Array ( [id] => 70066665 ) mysqli_result Object ( [current_field] => 0 
[field_count] => 230 [lengths] => [num_rows] => 0 [type] => 0 )

The fact that these are showing the correct serial number and row lengths, I know that the dashboard page and hyperlink code are working, as well as my SQL connection. I feel like there may be an issue in the way I've created the query on Display.php where it just isn't grabbing or matching correctly.

Here is the code:

Dashboard.php

<?php
$query1 = "SELECT * FROM staging;";
$result1 = mysqli_query($connect,$query1);
while($row = mysqli_fetch_array($result1)){
?>
    <tr>
    <td><? echo $row['workOrderPacket'];?>&nbsp;</td>
    <td><? echo $row['workOrderNum'];?>&nbsp;</td>
    <td><? echo $row['date'];?>&nbsp;</td>
    <td><? echo $row['utility'];?>&nbsp;</td>
    <td><? echo $row['serviceName'];?>&nbsp;</td>
    <td><? echo $row['address'];?>&nbsp;</td>
    <td><? echo $row['serialNumber'];?>&nbsp;</td>
    <td><?php echo '<a href="Display.php?   id='.$row['serialNumber'].'">'.$row['serialNumber'].'</a>'; ?>  </td>   
    </tr>
<?}?>
</table>

Display.php

<?php
//if(isset($_POST['submit'])) 
if(isset($_GET['id'])) 
{

$query1 = "SELECT * FROM staging WHERE stageID = ".$_REQUEST['id'].";";
$result1 = mysqli_query($connect,$query1);

while($row = mysqli_fetch_array($result1)){
?>
/////20 HTML tables filled with values from database
/////

1 Answer 1

1

In your hyperlink, you set the id using serialNumber but in your display.php, you are querying the result using stageID.

Sign up to request clarification or add additional context in comments.

1 Comment

I see, I did that in my statement for another page that uses a drop down and it populates all of the tables fine. I though I needed to do that in order to match the selected value to the primary key in the staging table so it knows which row to use. I just swapped it and it worked perfect! Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.