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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:42:11+00:00 2026-05-24T07:42:11+00:00

I’m trying to make a loop that will output this: 08:00 08:15 08:30 08:45

  • 0

I’m trying to make a loop that will output this:

08:00
08:15
08:30
08:45
09:00
09:15
09:30
09:45
...etc

I need it to go from 08:00 to 17:00.

Here’s my code so far:

function echo_datelist ($i, $j, $day, $month, $year)
{
    $time = str_pad($i, 2, '0', STR_PAD_LEFT).':'.str_pad($j, 2, '0', STR_PAD_LEFT);            
    $date = strtotime("$month $day $year $time:00");
    $sql = mysql_query("select b.room_type, c.name from bookings as b, customers as c where b.the_date='$date' and b.id_customer=c.id");
    
    echo $time.'<br />';
}

for ($i = 8; $i <= 16; $i++)
{
    for ($j = 0; $j <= 45; $j+=15)
        echo_datelist($i, $j, $day, $month, $year);
    
    echo_datelist(17, 0, $day, $month, $year);
}

The problem is, it is outputting a 17:00 in between each hour, example:

08:00
08:15
08:30
08:45
17:00
09:00
09:15
09:30
09:45
17:00

p.s. I know I shouldn’t be making iterated trips to the database, but I’ll solve that problem after this one.

  • 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-05-24T07:42:11+00:00Added an answer on May 24, 2026 at 7:42 am

    You need to move the last line outside of the outer for loop.

    for ($i = 8; $i <= 16; $i++){
      for ($j = 0; $j <= 45; $j+=15){
        //inside the inner loop
        echo_datelist($i, $j, $day, $month, $year);
      }
      //inside the outer loop
    }
    //outside the outer loop
    echo_datelist(17, 0, $day, $month, $year);
    

    In plain terms, you are saying:

    For each hour between 8 and 16
      For each 15 minute interval
        Echo the time
      End
      Echo 17:00
    End
    

    Instead of:

    For each hour between 8 and 16
      For each 15 minute interval
        Echo the time
      End
    End
    Echo 17:00
    

    I would consider performing your sql query for all hours of the day and then picking out the ones within the time from, otherwise you be doing an sql query for each 15 minute interval (37 queries with your sample data)

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

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

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.