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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:14:29+00:00 2026-05-23T01:14:29+00:00

with my current query and loop: $sched = mysql_query(SELECT * FROM `shows` ORDER BY

  • 0

with my current query and loop:

$sched = mysql_query("SELECT * 
FROM  `shows` 
ORDER BY  `shows`.`show_time` ASC")
or die(mysql_error());  


echo "<ul>";

while($row = mysql_fetch_array($sched)){
echo "<li><a href=\"#$row[id]\">";
echo $row['title'];
echo "</li>";
}
echo "</ul>";

This works great for displaying my results like this:

  • Name of show 1
  • Name of show 2
  • Name of show 3

However, I want to add an item to the list at the beginning of every change in day so it would display as follows:

  • Monday
  • Name of show 1
  • Name of show 2
  • Tuesday
  • Name of show 3
  • Wednesday
  • Name of show 4

I can’t quite wrap my brain around the loop needed to do this. It might be helpful to know that the field ‘show_time’ is a datetime type, so it has the information for both time and day of week.

Thanks.

  • 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-23T01:14:30+00:00Added an answer on May 23, 2026 at 1:14 am

    Simple tweak:

    echo "<ul>";
    $curDay='';
    while($row = mysql_fetch_array($sched)){
       $d=date('l',strtotime($row['show_time']));
       if($d!=$curDay){
         echo '<li>'.$d.'</li>';
       }
       $curDay=$d;
       echo '<li><a href="#',$row['id'],'">',$row['title'],"</li>";
    }
    echo "</ul>";
    

    Initialize $curDay, and then each time through the loop, check to see if the particular day is different than the last time through the loop (or different from the initial value)

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

Sidebar

Related Questions

My current query reads: SELECT entry_id, user_id, cat_id, AVG( rating ) as avg_rate FROM
I have a while loop from a query called $result . Inside this while
My query is: SELECT * FROM sites WHERE status = '1' ORDER BY id
the current SQL query works fine locally on MAMP 1.8.4 running MySQL 5.1.37. SELECT
Is is possible to query the current browser from within an applet? I would
I'm trying to get the query string from a string (not the current URL).
Query DECLARE v_vendor_id NUMBER; BEGIN FOR vp_rec IN ( SELECT * FROM vpprocess )
I have an ul list with a query and a while loop displaying the
Here is the updated question: the current query is doing something like: $sql1 =
My current LINQ query and example XML are below. What I'd like to do

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.