Problem with select in PHP

0

Notice: Undefined index: album_name in C: \ xampp \ htdocs \ gallery.php on line 69

Line 69:

        $album_name = $db->data[0]['album_name'];

This part code:

$db->query( "select * from fotos" )->fetchAll();
    if ( $db->rows >= 1 )
    {
        $album_name = $db->data[0]['album_name'];

        echo "<h1>" .  $album_name  . "</h1>\n";
        echo "<a href=\"album.php\" class=\"back\"><img src=\"images/left.png\"/> Voltar</a>";

I need to make a select to put the album name on my site, but I'm having this problem

    
asked by anonymous 07.02.2017 / 14:45

3 answers

2

PHP is reporting that the album_name index does not exist, give var_dump($db->data[0]) and see if it has any fields with the name album_name .

If you're in an album table, just try to JOIN:

$db->query("select * from fotos, albuns WHERE fotos.foto_album=albuns.album_id")->fetchAll();
    
07.02.2017 / 14:49
1

Make a JOIN as follows:

$db->query("select a.*, b.album_name AS album_name from fotos a INNER JOIN tabela_com_album_name b ON a.foto_album = b.id_do_album")->fetchAll();
    
07.02.2017 / 14:58
0

Are you sure that album_name is the correct column name in your database? As they said, give var_dump or print_r to see exactly what's coming from your query.

    
07.02.2017 / 14:51