Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7741435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:01:46+00:00 2026-06-01T09:01:46+00:00

I have 3 category pages for a photography website that are loaded dynamically from

  • 0

I have 3 category pages for a photography website that are loaded dynamically from a mysql database, and that works fine, but i would like to add sub-categories or “albums” in each category. This also needs to work dynamically because the website is for someone not technically minded.

So I think I have an idea, just not fully sure how to execute it. In this first block of code is how the images are currently getting loaded (minus a bunch of html gumpf in $dynamicList that isn’t necessary at this stage).
In the second block of code I’ve edited it to be able to load images into separate ‘albums’. However, as it stands, it will load every image into each album.

So is there a way to use “GROUP BY” to load dynamicLists that only contain images that share the same value for the row “album_name” in the database?

Apologies if i haven’t explained myself very well. Any help will be much appreciated.

<?php
include "connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM images WHERE category = 'People' ORDER BY date_added DESC");
    while($row = mysql_fetch_array($sql)){ 
        $image = $row["image_name"];
        $src_img=imagecreatefromjpeg("photos/thumbs/thumb_".$image);
        $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
        $dynamicList .= '<img class="item" src="photos/thumbs/thumb_'.$image.'"/>';
    }
mysql_close();
?>
<div id="image_gallery">
<?php echo $dynamicList; ?>
</div>





<?php
include "connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM images WHERE category = 'People' ORDER BY date_added DESC");
    while($row = mysql_fetch_array($sql)){ 
        $image = $row["image_name"];
        $src_img=imagecreatefromjpeg("photos/thumbs/thumb_".$image);
        $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
        $dynamicList .= '<img class="item" src="photos/thumbs/thumb_'.$image.'"/>';

        $album = $row["album_name"];
        $albumList .= '<div class="album"><div class="album_title"><h2>'.$album.'</h2></div>'.$dynamicList.'</div>';
    }
mysql_close();
?>
<div id="image_gallery">
<?php echo $albumList; ?>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:01:47+00:00Added an answer on June 1, 2026 at 9:01 am

    Something like this? (untested)

    <?php
    include "connect_to_mysql.php";
    $sql = mysql_query("SELECT * FROM images WHERE category = 'People' ORDER BY date_added DESC");
    $albums = array();
        while($row = mysql_fetch_array($sql)){ 
            $image = $row["image_name"];
            $src_img=imagecreatefromjpeg("photos/thumbs/thumb_".$image);
            $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
            $listElement = '<img class="item" src="photos/thumbs/thumb_'.$image.'"/>';
    
            $albums["album_name"][]=$listElement;
        }
        $anames = array_keys($albums);
        $albumList = "";
        foreach($anames as $albumName){
                $albumList .= '<div class="album"><div class="album_title"><h2>'.$albumName.'</h2></div>'.implode($albums[$albumName]).'</div>';
        }             
    mysql_close();
    ?>
    <div id="image_gallery">
    <?php echo $albumList; ?>
    </div>
    

    I don’t think a GROUP BY clause actually helps you, though you could implement a different solution if you knew they were in album order – you’d just have to check for when it transitions the the next album…. well, now that I’m thinking about it, maybe that’s a little simpler…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have category model that has a tree structure. In my database I have
i have created a photography website with an admin page that uploads photos to
I have a problem with displaying data from mysql database. My client requires to
I have a list of pages that are dynamically generated with a echo statment.
I have a page set up to show only posts from one category, which
I have a category system that is related many-to-many with posts. How can I
I have created a category template in Wordpress for all posts that are in
I have a coupon code site. On some category pages I'm limiting it to
We have several pages generated using PHP on our website with the following titles
We have a LIST of web pages that we use as News items on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.