dsz1966 2014-10-29 03:43
浏览 46
已采纳

如何从mysql表中选择多行?

I have a php script that is supposed to get multiple rows from a table and then wrap each row as an array into another array.

$comQy = "SELECT * FROM comments WHERE user = '$user' ORDER BY DESC;";
$comSt = $db->prepare($revQy);
$comRes = $comSt->execute();
$coms = $comSt->fetchAll();

Later in the page, I try to echo one of the elements of the array and then it doesn't work but doesn't return an error.

<div id="comUser">
<?php echo $coms[0]['user'] ?>
</div>

I appreciate all help and I am sorry if I have made a fairly simple mistake in the php script.

  • 写回答

3条回答 默认 最新

  • douwen5985 2014-10-29 03:52
    关注

    This could be the problem of

    • missing the field name for the ORDER BY clause in the SQL query
    • missing the variable declaration $revQy
    • missing the object variable declaration $revSt

    $comSt = $db->prepare($revQy);
    $comRes = $revSt->execute();

    Enabling error reporting is a good practice during development. Add these lines of code at the top of your script.

    error_reporting(E_ALL);
    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入