繁体   English   中英

$行不再起作用

[英]$rows doesnt work anymore

我试图将可用的mysql脚本升级到mysqli,但是$ rows变量遇到了一些问题。$ rows不再返回任何内容。 返回blanc。

这是我的代码:\\

<?php
    $host = "***";
    $user = "***";
    $pwd = "***";
    $db_name = "name";

    $link = mysqli_connect($host, $user, $pwd, $db_name)or die("cannot connect"); 



    $sql = mysqli_query($link, "SELECT * FROM foto ORDER BY id DESC LIMIT 25") or die(mysqli_error($link));
    //var_dump($sql);


    while ($rows = mysqli_fetch_assoc($sql))
    {
       echo "<img class='littleshow'"."id='foto".$rows[$id]."'src='".$rows[$foto]."' onclick='Bigscreen(this)'></img>";
    } 
?>

感谢您的帮助:)

变量$ id和$ foto没有在任何地方定义,将其更改为该变量,您将看到回显输出,并假设查询返回了行。 ($ rows [$ id] = $ rows ['id'])

while ($rows = mysqli_fetch_assoc($sql))
{
    echo "<img class='littleshow'"."id='foto".$rows['id']."'src='".$rows['foto']."' onclick='Bigscreen(this)'></img>";
}

echo $rows; 返回空白意味着查询没有返回任何行。

还有必要在PHP中设置完整的错误报告以查看可能的错误:

error_reporting(E_ALL);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM