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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:12:45+00:00 2026-06-02T05:12:45+00:00

Ive managed to loop through a table and get the difference in days between

  • 0

Ive managed to loop through a table and get the difference in days between 2 dates adjacent to each other in the table.

Multiple entries have the same date, i have it now that when that date changes, it displays an image however i want it to display the image as many times as the difference in date

$sql = mysql_query("SELECT * FROM Films_Info") 
 or die(mysql_error()); 

 $last_value = null;

while ($row = mysql_fetch_assoc($sql)) {

  if (!is_null($last_value)) {
  $a = new DateTime($row['FilmRelease']);
  echo "<p>".$row['FilmName']."</p>";
  $interval = $a->diff(new DateTime($last_value));
  //echo $interval->format('%d days');
  $i = 0;

}
$howManydays = $interval->days;

for ( $i; $howManydays; $i++) {
    echo "<img src=\"day.jpg\" />";
    $howManydays = 0;

}

  $last_value = $row['FilmRelease'];
}
  • 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-02T05:12:47+00:00Added an answer on June 2, 2026 at 5:12 am

    for ( $i = 0; $i < $howManydays; $i++) The second is a conditional statement telling when the loop should stop.

    The first section in the for loop where it says $i = 0 initialized the variable $i to 0 and then tests the condition $i < $howManydays.

    Let’s say $howManydays equals 1. That means 0 < 1, so the loop will perform.

    At the end of the loop, the third section is called ($i++), so $i is incremented and now equals 1. The second section is called again to test conditions $i < $howManydays which is asking if 1<1 which it’s not, so the loop will exit.

    So if $howManydays is greater than 0, the loop should happen the integer amount that is in $howManydays.

    You will want to remove $howManydays = 0; within the for loop, if you don’t want it to only fire once.

    The for loop

    for ( $i = 0; $i < $howManydays; $i++){
      // ...
    }
    

    is somewhat equivalent to the while loop:

    $i = 0;
    while ( $i < $howManydays ){
      // ...
      $i++;
    }
    

    http://php.net/manual/en/control-structures.for.php for more information

    In your code above, you should also check if interval was set. You should probably just do an if rather than a while, if only need one interval.

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

Sidebar

Related Questions

I've managed to get one stock table to display in the cart page when
Thanks to help in here I've managed to recursively loop through all the controls
I've managed to get a PNG overlay to appear over an asp:hyperlink image, but
I've managed to get my pthreads program sort of working. Basically I am trying
I've managed to get the original filename of a photo stored in the asset-library
I've managed to get a JSON output from my database for use with jQuery
I've managed to get my thread running and stopping safely but what I would
I've started learning clojure and I managed to get a few of the problems
I'm using XAudio2 with SlimDX and I've managed to get it playing a short
I've managed to load a texture with TextureLoader.LoadFromFile(), and provided it with Color.Black.ToArgb() for

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.