I am using a framework, and I am having an issue with getting the results of this particular associative array. All others work except for this one and I am not sure why. This one only returns one result. Here is what I have in my model:

    public function listStats($id) {
        $sql = DB::inst()->query( "SELECT * 
            FROM ".
                TP."tracking 
            WHERE 
                mID = '$id' 
            GROUP BY 
                mID" 
        );
        $data = array();
        if($sql->num_rows > 0) {
            while($row = $sql->fetch_assoc()) {
                $data[] = $row;
            }
            return $data;
        }
    }

And here is what I have in my view:

        <?php foreach($this->listStats as $k => $v) : ?>
        <tr>
            <td>
                <?php echo clean($v['email']); ?>
            </td>
        </tr>
        <?php endforeach; ?>

Any help with figuring this out is greatly appreciated.

Hi,

What framework are you using?

can you var_dump or print_r this ?

listStats($id);

and this

$this->listStats

what do you get?

I am assuming that $this->listStats is a method of the view class?

try this first... put this before the closing bracket of the method listStats;;

    return $data;
    } // closing bracket of method listStats..

like this ..

    public function listStats($id) {
$sql = DB::inst()->query( "SELECT *
FROM ".
TP."tracking
WHERE
mID = '$id'
GROUP BY
mID"
);
$data = array();
if($sql->num_rows > 0) {
while($row = $sql->fetch_assoc()) {
$data[] = $row;
}

}

    return $data;
}

Also, since you are querying a specific mID and then grouping by the same field, it's correct to get just a row. So try to change the GROUP BY clause. Bye!

HMM, the GROUP BY was a later addition because it wasn't working, but removing it makes it work now. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.