[英]Passing a database value from html table hyperlink to SQL query on next page
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.
我已经使用下拉框成功完成了此操作,并获得选择,然后使用提交按钮进行发布,该按钮将成功填充Display.php中的表。 However, I'm now using an html table that fills with values as a list and uses the serial number as a hyperlink.
但是,我现在使用的是一个html表,该表以值的形式填充列表,并将序列号用作超链接。
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. 当用户选择链接并打开Display.php时,我想获取与该链接/行关联的序列号,并在display.php页面的SQL查询中使用它,以便它可以将该序列号与中的stageID匹配我的登台表,然后选择该行的所有值。
In the following code, if I debug the $_GET array, it shows the correctly chosen serial number. 在下面的代码中,如果我调试$ _GET数组,它将显示正确选择的序列号。 If I debug/print $_GET and $result1, I get:
如果我调试/打印$ _GET和$ result1,则会得到:
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. 这些事实显示正确的序列号和行长,我知道仪表板页面和超链接代码以及我的SQL连接都可以正常工作。 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.
我觉得在Display.php上创建查询的方式可能存在问题,只是查询没有正确匹配。
Here is the code: 这是代码:
Dashboard.php Dashboard.php
<?php
$query1 = "SELECT * FROM staging;";
$result1 = mysqli_query($connect,$query1);
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><?php echo '<a href="Display.php? id='.$row['serialNumber'].'">'.$row['serialNumber'].'</a>'; ?> </td>
</tr>
<?}?>
</table>
Display.php 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
/////
在您的超链接中,使用serialNumber设置ID,但在display.php中,您使用stageID查询结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.