php - 如何在 php 中回显行值?

标签 php mysql

我正在尝试回显每行的值。 我尝试了这个... while ($row = mysqli_fetch_assoc) {...} 但它每次在循环的特定部分打印行的最后一个值。 另外,我创建了一个数组,并在 while 循环中分配了值,但它不起作用。 你能帮我吗?

$query= mysqli_query($con, "SELECT * FROM db WHERE user='$user' AND deleted='no' ORDER BY id DESC LIMIT 6");

while ($row = mysqli_fetch_assoc($query)) {
$link="index.php?id=". $row['id']; //wrong value

if ($row["user"] == 'User 1') {

$id=$row['id'];
$tags=$row['tags'];
$token = strtok($tags, ",");



echo "<div class='thisdiv'>
<a href='../games/avery/index.php?id=$id'><img src='../images/games/Preview.png ' ></a><br><p class='font-size-bold'>Tags</p>"; //correct $id

最佳答案

您的代码允许 SQL 注入(inject),请使用语句排除这种可能:

$query= $con->prepare("SELECT * FROM db WHERE user=? AND deleted=? ORDER BY id DESC LIMIT 6");
$no='no';
$query->bind_param('ss',$user,$no);
$query->execute();
$result=$query->get_result();
while ($row = $result->fetch_assoc()) {

if ($row["user"] == 'User 1') {

$id=$row['id'];
$tags=$row['tags'];
$token = strtok($tags, ",");



echo "<div class='thisdiv'><a href='../games/avery/index.php?id=$id'><img src='../images/games/Preview.png ' ></a><br><p class='font-size-bold'>Tags</p>"; //correct $id
    }
}

关于php - 如何在 php 中回显行值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59213179/

相关文章:

php - 如果 $_POST 是 "empty"或零,我如何检查 PHP?

php - 将定界字符串转换为关联数组

mysql - 如何通过sql显示投票结果

mysql - 在使用 Entity Framework Code First 和 mysql 时强制 engine=innodb

php - 使用php函数从表中转换值数据

mysql - 使用 DISTINCT 时无法从数据库查询所有数据

php - 解密使用 wp_hash() 生成的散列字符串

java发送json到php并插入mysql,但返回null

php - 通过 Web 浏览器 (PHP) 重新启动 Linux 服务器

mysql根据条件获取多表的计数