Jump to content

[SOLVED] Prepared statement only returning first row/entry...


cgm225

Recommended Posts

I have the following method that returns photo entries from a MySQL database.  However, even when there are multiple database entries/rows, the array only returns with one entry.  I have tried to debug it, and it does not seem to be a problems with the limits or binding.

 

Any ideas?

 

    public function findPhotos() {
        $query = 'SELECT id, filename, caption, date, location, album, timestamp
                    FROM images WHERE album = ?
                    ORDER BY filename ASC LIMIT ?, ?';
        $statement = $this->connection->prepare($query);
        $statement->bind_param('sii', $this->albumData['id'], $this->skip, $this->numberRows);
        $statement->bind_result($id, $filename, $caption, $date, $location, $album, $timestamp);
        $statement->execute();
        while($statement->fetch()) {
            $this->photoData = array(
                'id'         => $id,
                'filename'   => $filename,
                'caption'    => $caption,
                'date'       => $date,
                'location'   => $location,
                'album'      => $album,
                'timestamp'  => $timestamp
            );
        }
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.