gpt4 book ai didi

php - 每行mysql数据的超链接

转载 作者:行者123 更新时间:2023-11-29 00:47:53 25 4
gpt4 key购买 nike

<?php

require 'database.php';
$query = "SELECT id, date, ponumber FROM so";

$result = $mysqli->query($query) or die(mysqli_error($mysqli));

if ($result) {
echo "<form method='post' action='delete.php'>";

echo "<table cellspacing='0' cellpadding='15' border='1'>
<th >DELETE</th>
<th >VIEW</th>
<th >ID</th>
<th >DATE</th>
<th >PO NUMBER</th>";

while ($row = $result->fetch_object()) {

$date = $row->date ;
$ponumber = $row->ponumber;
$id = $row->id;
//put each record into a new table row with a checkbox
echo "<tr>
<td>
<input type='checkbox' name='checkbox[]' id='checkbox[]' value=$id />
</td>
<td>
$id
</td>
<td>
<a href="view.php">view</a>
</td>
<td>
$date
</td>
<td>
$ponumber
</td>
</tr>";
}

echo "</table><p><input id='delete' type='submit' class='button' name='delete'

value='Delete Selected Items'/></p></form>";}
?>

我有一种在线订单表格,可以让销售代表输入销售订单,我已经使用上面的代码完成了插入和删除,现在我希望每一行都是一个超链接,这样当他们单击查看时,它将仅显示已单击的行,在我上面的代码中,如果您单击:查看“所有详细信息将显示,我如何才能只显示我将要单击的行以显示记录的详细信息!

最佳答案

您需要传递 url 中的 id,如果它在那里,您需要读取它。

例如

<?php
require 'database.php';
$query = "SELECT id, date, ponumber FROM so";
/* Edit 1 */
if (!empty($_GET['id'])) {
$query .= " WHERE id = " . mysql_real_escape_string($_GET['id']);
}
/* Edit 1 end */
$result = $mysqli->query($query) or die(mysqli_error($mysqli));
if($result) {
echo "<form method='post' action='delete.php'>";
echo "<table cellspacing='0' cellpadding='15' border='1'>
<th >DELETE</th><th >VIEW</th><th >ID</th><th >DATE</th><th >PO NUMBER</th>";
while ($row = $result->fetch_object()) {
$date = $row->date ;
$ponumber = $row->ponumber;
$id = $row->id;
//put each record into a new table row with a checkbox
echo "<tr>
<td><input type='checkbox' name='checkbox[]' id='checkbox[]' value=$id /></td>
<td>$id</td>
<td>";
/* Edit 2 */
echo "<a href='view.php?id=$id'>view</a>";
/* Edit 2 End */
echo "</td>
<td>$date</td>
<td>$ponumber</td></tr>";
}
echo "</table><p><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Items'/></p></form>";}
?>

风格建议:

不要这样做/停止这样做:

echo "<form method='post' action='delete.php'>"; 
echo ...
while

你回显的是一个静态字符串。相反,做:

?>
<form method='post' action='delete.php'>
...
<?php
while

它更易于阅读和维护。

关于php - 每行mysql数据的超链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9822365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com