gpt4 book ai didi

php - 循环使用 PHP 和 MySQL 的动态链接

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

我正在为一个 self 项目学习 PHP 和 MySQL,显然我陷入了困境。我正在尝试制作的网站包括提交表格并对其进行审查。我设法创建一个循环,以显示所有已提交且尚未处理的表单(因此,容易进行审查),并且每个表单都有自己的链接,该链接重定向到该表单包含的数据。

    $query = mysqli_query ( $conn, "SELECT * FROM members WHERE username = '$myrealusername' LIMIT 1" );
$result = $query->fetch_assoc ();
$id = $result ['id'];
echo 'Welcome ' . $id . '. <br>';

$quer = mysqli_query ( $conn, "select count(*) as total from carforms where aboveid='$id' and processed='0'" );
$data = $quer->fetch_assoc ();
$total = $data ['total'];
$quer = mysqli_query ( $conn, "select fullname as CurrentName, formid as CurrentForm from carforms where aboveid='$id' and processed='0'" );
for ($x=1; $x<=$total; $x++) {
$data = $quer->fetch_assoc ();
$forms = $data ['CurrentName'];
$forma = $data ['CurrentForm'];
echo 'Form No.'. $forma .' by: ' .$forms .'<a href="reviewform.php">Click here to review</a>.<br>';
}
?>

这就是它显示的内容:

 Welcome 2. 
Form No.1 by: John Miller Click here to review.
Form No.2 by: John Miller Click here to review.
Form No.3 by: Mike Tywell Click here to review.
Form No.4 by: John Miller Click here to review.
Form No.5 by: Eric Paton Click here to review.

问题是,我不知道如何将不同的数据传递到 MySQL carform 表中显示的每个链接,该表还包括汽车类型、汽车颜色等数据,并且每个人都不同。

提前致谢。

最佳答案

您需要将其添加为查询字符串,例如

  echo  'Form No.'. $forma .' by: ' .$forms .'<a href="reviewform.php?id='.$row['id'].'">Click here to review</a>.<br>'; 

仅供引用,你可以让这变得更简单

 $query = mysqli_query ( $conn, "SELECT * FROM members WHERE username = '$myrealusername' LIMIT 1" );
$result = $query->fetch_assoc ();
$id = $result ['id'];
echo 'Welcome ' . $id . '. <br>';

$quer = mysqli_query ( $conn, "select id,fullname as CurrentName, formid as CurrentForm from carforms where aboveid='$id' and processed='0'" );
while($data= mysqli_fetch_array($quer)) {

$forms = $data ['CurrentName'];
$forma = $data ['CurrentForm'];
echo 'Form No.'. $forma .' by: ' .$forms .'<a href="reviewform.php?id='.$data['id'].'">Click here to review</a>.<br>';
}
?>

或者类似的东西。

关于php - 循环使用 PHP 和 MySQL 的动态链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39371117/

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