SQL with PHP - Problem in SELECT

0

I have an album, so I click on the album, it's just to show the photos that are in the database with the id of the selected album, I click on the album and the photos from the album with the selected id and the id of the album are coming. another album too, come all photos in 1 album only, my select is like this:

select fotos.*, albuns.album_name from fotos 
INNER JOIN albuns ON fotos.foto_album = albuns.album_id

I get the album_id variable from the page get:

$album_id = $_GET['id'];
    
asked by anonymous 20.02.2017 / 16:34

1 answer

1

You should use WHERE .

SELECT fotos.*, 
       albuns.album_name 
FROM   fotos 
       INNER JOIN albuns 
               ON fotos.foto_album = albuns.album_id 
WHERE  albuns.album_id = 123456

In this case 123456 is $album_id , for example:

$album_id = mysqli_real_escape_string($sql, $_GET['id']);

mysqli_query($sql, '    
    SELECT fotos.*, 
           albuns.album_name 
    FROM   fotos 
           INNER JOIN albuns 
                   ON fotos.foto_album = albuns.album_id 
    WHERE  albuns.album_id = "'.$album_id.'"
');

The WHERE will only get the data where the album_id of the albuns is equal to the value of the $album_id .

    
20.02.2017 / 16:43