我迷路了。我想要做的是,我希望我的网站允许用户在我的数据库中选择某一行(记录),然后将它们重定向到另一个网页,向他们显示有关该特定记录的完整信息..我不知道知道如何使用动态表格/文本将这两个网页连接在一起.. 以下是我的代码的一部分:(这是第一个网页:)
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>
这将用户重定向到下一页但我的问题是它继续显示相同的记录,这是我数据库中的第一条记录。
答案 0 :(得分:0)
1-考虑page1.php是用户选择记录的第一页,然后在page2.php中显示完整的详细信息。
for page1.php
您需要发送一些参数,例如记录ID或任何其他密钥,以便能够识别记录并选择数据库中的详细信息。
例如: 记录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);
答案 1 :(得分:0)
如果您希望用户在点击特定行时加载特定记录,则必须确保将其重定向到特定网址。在您的示例中,您的工作时间为<a href="ViewSpecificRFQ.php">
,因此表格中的每一行都会有相同的链接,然后是相同的目标网页。
您可能需要<a href="ViewSpecificRFQ.php?recordId=<?php echo $row_rfqrecord['RFQ_ID'] ?>">
之类的内容,然后在您的目标网页中,您将根据$_GET['recordId']
中的密钥执行查询。
编辑:执行问题
你使用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
}
?>