douyabu1528 2016-11-22 23:45
浏览 74
已采纳

pdo数组如何从数据库中获取所有信息

I need to fetch all the info from a query , so I can use it for other purposes, the issue is that I'm just getting 1 result of each kind and I need them all, here is my script:

<?php
  require_once 'init.php';
  $base_datos = DB::getInstance();

  $base_datos->query ("SELECT lname, fname, category,user_id, SUM(points) as Point, SUM(amount)as Amount FROM request GROUP BY user_id");
   $get_info = $base_datos->results();
   $real_info = $get_info[0];
   $name = $real_info->lname;
   $last_name = $real_info->fname;
   $categories = $real_info->category;
   echo "$name";
   ///var_dump ($get_info);
  ?>

when echo $name all i get is one name i need to get them all and so on with the other value, when i do var_dump i got all i need, but i need to loop through,I'd searched all around and was not lucky. enter image description here

this is what I'm trying to output on php page

  • 写回答

1条回答 默认 最新

  • douxin9135 2016-11-22 23:50
    关注

    I'm assuming $get_info is an array of objects based on how your code is currently written. Right now you're setting the first record of $get_info to $real_info.

    So to access all of the records loop through $get_info like this.

    foreach($get_info as $real_info) {
        echo $real_info->fname.' '.$real_info->lname;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java面向对象程序设计
  • ¥20 Keil uVision5创建project没反应
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能