doujiurong7210 2017-04-12 22:46
浏览 80
已采纳

将数据库值从html表超链接传递到下一页上的SQL查询

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条回答 默认 最新

  • driuwt9557 2017-04-12 23:25
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址