Welcome Guest, Not a member yet? Register   Sign In
How to group entries in table according to one column
#1

[eluser]landitus[/eluser]
Hi! I have the following table:

id | album | photo
--------------------
1 | 1 | photo1.jpg
2 | 1 | photo2.jpg
3 | 2 | photo3.jpg

I would like to know how can I retrieve the table data and then loop throught the records so that for each album I can list the corresponding photos.
#2

[eluser]cmgmyr[/eluser]
Code:
SELECT * FROM `albums` WHERE `album` = 1

http://ellislab.com/codeigniter/user-gui...eries.html
http://ellislab.com/codeigniter/user-gui...sults.html
#3

[eluser]landitus[/eluser]
Thanks cmgmyr, but what if I don't know how many albums, and just need to loop through the whole table and get all albums with their corresponding photos?
#4

[eluser]cmgmyr[/eluser]
Then you can do something like this:
Code:
SELECT DISTINCT `album` FROM `albums` ORDER BY `album` ASC

I normally set up an "albums" page then a "photos" page. Once they click on an album then they will get directed to the photos page, which shows all of the photos for that album.




Theme © iAndrew 2016 - Forum software by © MyBB