walter alexander walter alexander - 1 year ago 151
MySQL Question

pdo array how fetch all info from database

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:

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

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download