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 7813757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:58:42+00:00 2026-06-02T04:58:42+00:00

I have my code written to select images from my database and display them,

  • 0

I have my code written to select images from my database and display them, grouped by month. I would like every ‘month of photos’ to be in its own “container” div. I cannot figure out how to do this while in a WHILE LOOP. I think I need a way to tell if the next row of data, that is going to get iterated, is a new month or not. Any suggestions?

My code:

<?php

if (isset($_COOKIE['user_id']))
{
if (!isset($_GET['user_id']))
{
$user_id= $_COOKIE['user_id'];
}
else
{
$user_id= $_GET['user_id'];
}

$connect= mysqli_connect("localhost", "root", "", "si");
$query= "SELECT * FROM posts WHERE user_id= $user_id ORDER BY date DESC";

$result= mysqli_query($connect, $query)
or die('error with query');
$date = "0";

while ($row= mysqli_fetch_array($result)) {

if ($date != $row['date']) {
 echo "<p> ".$row['date']."</p><br/>";
 $date = $row['date'];
}

echo '<img src="'.$row['picture']. '"/>' . "<br/>";
}
}
?>

Here is how it should look…

enter image description here

For example, the FEB 2012 month should be in a different container div than JAN 2012.

  • 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-02T04:58:42+00:00Added an answer on June 2, 2026 at 4:58 am

    It is quite easy to implement this at the same place where you create the month header.

    $first = true;
    if ($date != $row['date']) {
        if ($first) {
            $first = false;
        } else {
            echo "<\div>";
        }
        echo "<div><p> ".$row['date']."</p><br/>";
        $date = $row['date'];
    }
    

    Then you have to close the last div after the while loop by calling:

    echo "</div>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the code to select a folder from the SDCard and its
In our application, I have seen code written like this: User.java (User entity) public
Hi I have written code like this @Id @Column(nullable=false) @GeneratedValue(strategy=GenerationType.AUTO) public int getUserID() {
I have a table in MySQL database from which I want to select a
I have written the following code in MATLAB to process large images of the
i have code written something like this. if(!isset($cid)) { echo <script type=\text/javascript\>alert('OOps, Something went
I have written code which should call MSSQL 2005 procedure from my servlet. The
I have written a code where i am frequently tripping to database which is
I have code written in c, which contains some complex algorithms and I want
I'm working on a video codec for OMAP3430. I already have code written in

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.