3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Biiim
0

i don't understand your question do you want image in album table belong to perticular album then you have to also insert the id of image from your image or photo table in album table

0

Thats because $albums = Album::find_all(); returns an array

public static function find_all() {
    return self::find_by_sql("SELECT * FROM ".self::$table_name);
}
public static function find_by_sql($sql="") {
    global $database;
    $result_set = $database->query($sql);
    $object_array = array();
    while ($row = $database->fetch_array($result_set)) {
        $object_array[] = self::instantiate($row);
    }
    return $object_array;
}

You will want a starter line like $album = new Album(); and careful not to overwrite the object later on!

The structure you want is:

album table
album_id,album_title....etc - no data about any photo

and either

photo table
photo_id,album_id,..... - only photo data(and if no reference table, include the album id)

or

photo_album_ref table
id,album_id,photo_id - links up that photos 3, 5 and 11 are in album 1 etc

the latter reference table has the benefit of being able to assign a single photo to any number of albums

Then you just find out what photos are in a album by either:

SELECT * FROM albums a 
LEFT JOIN photos p ON a.album_id = p.album_id
WHERE a.album_id = 3

SELECT * FROM albums a
LEFT JOIN photo_album_ref `par` ON a.album_id = par.album_id
LEFT JOIN photos p ON par.photo_id = p.photo_id
WHERE a.album_id = 3;

Edited by Biiim: typo

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.