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

  • Home
  • SEARCH
  • 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 6332615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:17:54+00:00 2026-05-24T18:17:54+00:00

I need help with my php script. I am working on a script that

  • 0

I need help with my php script. I am working on a script that allows my users to choose a time for their class. The time list is locked on a 24 hour grid, meaning a class can only happen every hour.

The goal of this script is to show the user a simple form with the available times.

There are 24 possible times in a day for one room. *I have three rooms.*

I understand how to make the form later on, what I don’t get is how to show available times if there are three rooms.

Here is what I got so far:

<?php
include 'db-connect.php';
if (isset($_GET['month']) && isset($_GET['day']) && isset($_GET['year'])) {

    $month = $_GET['month'];
    $day = $_GET['day'];
    $year = $_GET['year'];

    //string together date
    $date = $month."/".$day."/".$year;

    //return classes on this date
    $sql = mysql_query("SELECT start_time, server FROM classes WHERE date = '$date'");

    if (mysql_num_rows($sql)<=0) {

        echo "show all the times.";

    }else {

        $timelist = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24);
        $servers = array(1,2,3);

        while($query = mysql_fetch_array($sql)) {

                unset($timelist[$query['start_time'] - 1]);

        }
    }
}
?>

Database Example:

+---------------------------------------------------------------------------------------+
| classID | trainerID | type | date      | start_time | duration | server | define      |
+---------------------------------------------------------------------------------------+
| 1       | 1         | 12   | 08/7/2011 | 9          | 60       | 1      | dummy class |
+---------------------------------------------------------------------------------------+
  • 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-24T18:17:55+00:00Added an answer on May 24, 2026 at 6:17 pm

    Instead of your current strategy you could just store the number of arrays each time is found in, like:

    //define time list
    $timelist = array_fill(1, 24, 0);
    
    while($query1 = mysql_fetch_array($sql1)) {
    
        $timelist[$query1['start_time']]++;
    
    }
    
    while($query2 = mysql_fetch_array($sql2)) {
    
        $timelist[$query2['start_time']]++;
    
    }
    
    while($query3 = mysql_fetch_array($sql3)) {
    
        $timelist[$query3['start_time']]++;
    
    }
    
    $timelist = array_keys(array_filter($timelist, 'equals3'));
    
    function equals3($x){
        return $x == 3;
    }
    

    Now $timelist is an array of times that were found in all three queries. If you want an array of times that were missing from at least one query use this instead of the last few lines:

    $timelist = array_keys(array_filter($timelist, 'lessThan3'));
    
    function lessThan3($x){
        return $x < 3;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem, i'm working on a gallery php script and need help,
I need help rewriting online.php to -> /users/online and profile.php?id=3426 to -> /users/3426 and
I need help finishing this statement. It is frustrating that two of the PHP
I need to get a script working for our billing system (WHMCS) using their
I'm currently working on a PHP/MySQL script that does the following, in this order:
i need to set a crontab from a php script. i know that it
I need some help with creating a regex for my php script. Basically, I
I'm working on a PHP script that needs to communicate with a service REST
I need to develop a script using Wordpress PHP that will run with the
I need help to use jConfirm with this existing code (php & Jquery &

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.