dqcqcqwq38860 2014-10-31 10:40
浏览 51

在PHP上返回整个MYSQL表数据

I found this code once...

$sql_select = "SELECT * FROM users";
$rs_stuff = select($sql_select);

while ($res = mysql_fetch_assoc($rs_stuff)) {

echo ($res("Name")."<br />");

}

It works well, it returns all names found in "Name" col, the problem is I want it to make to return all data in that table, like if I just typed "SELECT * FROM users" on mysql, I don't understand much of PHP, I tried to do this:

echo("<br />
".$res);

But when trying to run this on the page, I just got a empty blank with "Array" written on it... Is it possible to do this without putting the col names in the php?

(Sorry about my English, it is not my main language.)

  • 写回答

6条回答 默认 最新

  • dsa4214 2014-10-31 10:41
    关注

    This happens because $res is a Array

    use:

    print_r($res);
    

    or if you want a better view of it:

    echo '<pre>';
      print_r($res);
    echo '</pre>';
    

    OR

    you can use:

    echo ($res["Name"]."<br />");
    

    also, on this second option, watch out for multidimensional arrays. Your $res might be one. In which case it will be:

    echo ($res[0]["Name"]."<br />");
    

    if you have only one result. I suggest you go with the first choice and see how your $res looks like before echoing strings ;)

    Either way, please find a good PHP tutorial as it is CLEAR that you lack basic knowledge of how to use and manipulate PHP code.

    Hope it helps! :D

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大