0

我迷路了。我想要做的是,我希望我的网站允许用户在我的数据库中选择某一行(记录),然后将他们重定向到另一个网页,该网页将向他们显示有关该特定记录的完整信息。我不知道如何使用动态表格/文本将这两个网页连接在一起。下面是我的代码的一部分:(这是第一个网页:)

mysql_select_db($database_rfq_portal, $rfq_portal);
$query_rfqrecord = "SELECT tblrfq.`RFQ_ID`, tblrfq.`Company_Name`, tblrfq.Service,
tblrfq.`Kind_of_Request`, tblrfq.Status, tblrfq.`Date` FROM tblrfq";
$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);


<form id="viewform" name="viewform" method="get" action="ViewSpecificRFQ.php">
<table width="716" border="1" align="center" cellpadding="5">
<tr>
<td>RFQ ID</td>
<td>Company Name</td>
<td>Service</td>
<td>Kind of Request</td>
<td>Status</td>
<td>Date</td>
</tr>
<?php do { ?>
  <tr>
    <td><a href="ViewSpecificRFQ.phpRFQID=<?php echo $row_rfqrecord['RFQ_ID'];?>"><?php echo $row_rfqrecord['RFQ_ID']; ?></a></td>
    <td><a href="ViewSpecificRFQ.phpRFQID=<?php echo $row_rfqrecord['RFQ_ID'];?>"><?php echo $row_rfqrecord['Company_Name']; ?></a></td>
    <td><a href="ViewSpecificRFQ.phpRFQID=<?php echo $row_rfqrecord['RFQ_ID'];?>"><?php echo $row_rfqrecord['Service']; ?></a></td>
    <td><a href="ViewSpecificRFQ.phpRFQID=<?php echo $row_rfqrecord['RFQ_ID'];?>"><?php echo $row_rfqrecord['Kind_of_Request']; ?></a></td>
    <td><a href="ViewSpecificRFQ.phpRFQID=<?php echo $row_rfqrecord['RFQ_ID'];?>"><?php echo $row_rfqrecord['Status']; ?></a></td>
    <td><a href="ViewSpecificRFQ.phpRFQID=<?php echo $row_rfqrecord['RFQ_ID'];?>"><?php echo $row_rfqrecord['Date']; ?></a></td>
  </tr>
<?php } while ($row_rfqrecord = mysql_fetch_assoc($rfqrecord)); ?>
</table>
}
</form>

这是将获得表单的网页..(我的代码的一部分)

$RFQID = $_GET['RFQ_ID'];
mysql_select_db($database_rfq_portal, $rfq_portal);
$query_rfqrecord = "SELECT * FROM tblrfq WHERE $RFQID";

$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);

mysql_select_db($database_rfq_portal, $rfq_portal);
$query_user = "SELECT tbluser.Username, tbluser.Password FROM tbluser";
$user = mysql_query($query_user, $rfq_portal) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);



<table width="716" border="0" align="center">
<tr>
  <th colspan="2" scope="row">RFQ ID:</th>
  <td><?php echo $row_rfqrecord['RFQ_ID']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Company Name:</th>
  <td width="511"><?php echo $row_rfqrecord['Company_Name']; ?></td>
</tr>
<tr>
  <th width="101" rowspan="2" scope="row">Address:</th>
  <th width="90" scope="row">Site A:</th>
  <td><?php echo $row_rfqrecord['Address_A']; ?></td>
</tr>
<tr>
  <th scope="row">Site B:</th>
  <td><?php echo $row_rfqrecord['Address_B']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Contact Number:</th>
  <td><?php echo $row_rfqrecord['Contact_Number']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Contact Person:</th>
  <td><?php echo $row_rfqrecord['Contact_Person']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Service:</th>
  <td><?php echo $row_rfqrecord['Service']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Bandwidth:</th>
  <td><?php echo $row_rfqrecord['Bandwidth']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Telco:</th>
  <td><?php echo $row_rfqrecord['Telco']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Account Manager:</th>
  <td><?php echo $row_rfqrecord['Account_Manager']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Status:</th>
  <td><?php echo $row_rfqrecord['Status']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Kind of Request:</th>
  <td><?php echo $row_rfqrecord['Kind_of_Request']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Date:</th>
  <td><?php echo $row_rfqrecord['Date']; ?></td>
</tr>
<tr>
  <th colspan="2" scope="row">Remarks:</th>
  <td><?php echo $row_rfqrecord['Remarks']; ?></td>
</tr>

</table>
</form>

这会将用户重定向到下一页,但我的问题是它一直显示相同的记录,这是我数据库中的第一条记录。

4

2 回答 2

0

1- 考虑 page1.php 是用户选择记录的第一页,然后在 page2.php 中显示完整的详细信息。

对于 page1.php

您需要发送一些参数,例如记录 ID 或任何其他键,以便能够识别记录并选择数据库中的详细信息。

例如: Record 1 一旦用户点击了这个链接,你必须在 page2.php 中做这样的事情,记住我们的参数是 record_id

<?php
$id = $_GET['record_id'];
//we have to check it for validity
//if id is an integer (numbers) then simply we can check it
//if(!is_numeric($id)) { die("invalid id") }

// now the id is there
//lets build query
$query = "SELECT * from tablename where id= '$id' ";
?>

对于您的代码,它必须是这样的://添加 where 子句 $query_rfqrecord = "SELECT * FROM tblrfq where RFQ_ID = '$id'";

$rfqrecord = mysql_query($query_rfqrecord, $rfq_portal) or die(mysql_error());
$row_rfqrecord = mysql_fetch_assoc($rfqrecord);
$totalRows_rfqrecord = mysql_num_rows($rfqrecord);
于 2013-02-14T10:48:26.903 回答
0

如果您希望用户在单击特定行时加载特定记录,则必须确保将他们重定向到特定 url。在您的示例中,您<a href="ViewSpecificRFQ.php">在您的 do-while 中拥有,因此表中的每一行都将具有相同的链接,然后是相同的目标页面。

您可能想要类似的东西<a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>">,然后在您的登录页面中,将针对您将拥有的键执行查询$_GET['recordId']

编辑:do-while 问题

您使用 do-while,因此在第一次迭代中您没有加载任何记录,因为 fetch 指令位于代码块的底部,因此您应该将其更改为:

<?php
while ($row_rfqrecord = mysql_fetch_assoc($rfqrecord)) {
    ?>
    <tr>
        <td><a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"><?php echo $row_rfqrecord['RFQ_ID']; ?></a></td>
        <td><a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"><?php echo $row_rfqrecord['Company_Name']; ?></a></td>
        <td><a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"><?php echo $row_rfqrecord['Service']; ?></a></td>
        <td><a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"><?php echo $row_rfqrecord['Kind_of_Request']; ?></a></td>
        <td><a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"><?php echo $row_rfqrecord['Status']; ?></a></td>
        <td><a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>"><?php echo $row_rfqrecord['Date']; ?></a></td>
    </tr>
    <?php
}
?>
于 2013-02-14T10:48:27.170 回答