gpt4 book ai didi

PHP 将变量从 while 循环传递到另一个页面上的 Select 查询

转载 作者:行者123 更新时间:2023-11-29 18:39:41 25 4
gpt4 key购买 nike

我有一个名为 prototype.php 的页面,并且有一个 while 循环,我在其中回显按钮。当您单击该按钮时,您将被重定向到 "proto.php?id=".$row['id'] 并且在该页面上需要显示一个表格,其中包含包含行的内容具有按钮的 id。但我不知道如何将变量从 prototype.php 传递到 "proto.php?id=".$row['id']

这是我的 while 循环:

    <?php
$sql = "SELECT * FROM theme";
$result = $con->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$your_url= "proto.php?id=".$row['id'];
echo '<a href="'.$your_url.'"><input type="button" value="'. $row["theme_name"].'"></a>';

}
} else {
echo "no results";
}
?>

这是"proto.php?id=".$row['id']:

$row = $_GET['id'];
// Attempt select query execution
$sql = "SELECT * FROM Norm LEFT JOIN Org ON norm.org_id = org.id LEFT JOIN Cluster ON norm.cluster_id = cluster.id LEFT JOIN Orden ON norm.orden_id = orden.id LEFT JOIN Users ON norm.user_id = users.id WHERE theme_id = $_GET['id']";
if ($result = mysqli_query($link, $sql)) {
if (mysqli_num_rows($result) > 0) {

echo "<table>";
echo "<tr>";
echo"<th>Norm Org</th>";
echo "<th>Norm id</th>";
echo "<th>Norm</th>";
echo "<th>Ordenen</th>";
echo "<th>Clusteren</th>";
echo "<th>Verantwoordelijke</th>";
echo "</tr>";

while ($row = mysqli_fetch_array($result)) {
if ($row['orden_name']) {
$data_list = $row['orden_name'];
} else {
$data_list = $dropdown_list;
}
if ($row['cluster_name']) {
$data_list2 = $row['cluster_name'];
} else {
$data_list2 = $dropdown_list2;
}
if ($row['user_name']) {
$data_list3 = $row['user_name'];
} else {
$data_list3 = $dropdown_list3;
}
echo "<tr>";
echo "<td>" . $row['org_name'] . "</td>";
echo "<td class='row_count'>" . $row['norm_id'] . "</td>";
echo "<td>" . $row['norm_name'] . "</td>";
echo "<td>" . $data_list . "</td>";
echo "<td>" . $data_list2 . "</td>";
echo "<td>" . $data_list3 . "</td>";
echo "</tr>";

}
echo "</table>";
// Free result set
mysqli_free_result($result);
}else{
echo "No records were found.";
}

} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

有人可以帮我吗?

最佳答案

proto.php 中更改此行:WHERE theme_id = '1'";

对此:WHERE theme_id = ". $_GET['id'] . ";";

关于PHP 将变量从 while 循环传递到另一个页面上的 Select 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45029837/

25 4 0
文章推荐: mysql - 运行时间错误: Object required
文章推荐: java - 魔石: converting JSON to Java object when the class has a List field