Show album data and images in my view |
[eluser]Lykos22[/eluser]
Hi, I 'd like some help please. I have 2 tables: Code: Albums with: What I want to do is to fetch all data from these two tables , loop through them and display them in my view so it should look something like portfolio section (2nd screenshot) of this template as the ending result. This is what I have so far in my controller: Code: // fetch all album data my view: Code: <?php foreach($albums as $album): ?> I'm not sure if this is the best way to do it as the running queries (which shown in Profiler) will be increase when more albums added. Is there a better way to do this ?? NOTE: the ending result in my view should be like the 2nd screenshot you see on the link.
[eluser]CroNiX[/eluser]
Use a join? 1 query to get all published albums and their images.
[eluser]CroNiX[/eluser]
something like: Code: $albums = $this->db Code: $last_album_id = 0; Probably not 100% correct, but should show you the way.
[eluser]Lykos22[/eluser]
Well I tried to do it using join but when I loop through the data I get them twice each time (cause currently I have 2 albums), like: album1 - images1 album1 - images1 album2 - images2 album2 - images2 I 'll have to test your way though, which has the if condition.* I also noticed that my view isn't correct. So basicly I need one loop to display the data, but each one should appear once. EDIT * still the same thing, I've tested it
[eluser]Lykos22[/eluser]
Some additional information: I've also tested the JOIN query Code: SELECT `albums` . * , `albumimages`.`image` Code: album_id, title, description, image What I actually want to display in my view is this: Code: album title 1 |
Welcome Guest, Not a member yet? Register Sign In |