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

The Archive Base Latest Questions

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

I got this script which looks up taken times in this table and then

  • 0

I got this script which looks up taken times in this table and then removes those times from these three arrays. The arrays are times 1-24.

The ultimate goal of this script is to compare all the missing times from these arrays and make one big array with only the available times.

The catch is it needs to check if a time is missing three times in a row. If it is, that time will not display in the final array.

For example:

<?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;

//define the queries
$sql1 = mysql_query("SELECT start_time, server FROM classes WHERE date = '$date' AND server = '1'");
$sql2 = mysql_query("SELECT start_time, server FROM classes WHERE date = '$date' AND server = '2'");
$sql3 = mysql_query("SELECT start_time, server FROM classes WHERE date = '$date' AND server = '3'");

//define time lists for each server
$timelist1 = range(1, 24);
$timelist2 = range(1, 24);
$timelist3 = range(1, 24);

//unset the arrays with the taken times for server 1
while($query1 = mysql_fetch_array($sql1)) {

    unset($timelist1[$query1['start_time'] - 1]);

}
//unset the arrays with the taken times for server 2
while($query2 = mysql_fetch_array($sql2)) {

    unset($timelist2[$query2['start_time'] - 1]);

}
//unset the arrays with the taken times for server 3
while($query3 = mysql_fetch_array($sql3)) {

    unset($timelist3[$query3['start_time'] - 1]);

}

//now see which times are missing three times in a row and make one final array of available times.

//code goes here...

}
?>
  • 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-24T15:54:35+00:00Added an answer on May 24, 2026 at 3:54 pm

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

    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;
    
    //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;
    }
    

    Edit for variable amount of servers.

    // Here you can list the servers you want to include in the query
    // In an array form so it can be filled easily
    $servers = array(1,2,4,5);
    $num_servers = count($servers);
    
    // Convert servers into queryable format
    $servers = '(\''.implode('\',\'', $servers).'\')';
    $query = 'SELECT `start_time`, COUNT(*) as `count` FROM `classes`
               WHERE `date` = \''.$date.'\' AND `server` IN '.$servers.' 
               GROUP BY `start_time`';
    $result = mysql_query($query);
    
    $timelist = array_fill(1, 24, 1);
    while($row = mysql_fetch_row($result))
        if($row[1] == $num_servers) // `start_time` is missing from at least one server
            unset($timelist[$row[0]]);
    $timelist = array_keys($timelist);
    
    // Now $timelist is an array of times that are available on at least one server from the query
    

    Please note that since your date variable comes from $_GET you should be very careful of MySQL Injection attacks. Someone could delete your whole database, or worse, if you don’t have the right protection in place. Please read this: http://www.learnphponline.com/security/sql-injection-prevention-mysql-php

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

Sidebar

Related Questions

I've got a template, a.html, which looks like this: <script type=text/javascript src=jquery-1.4.min.js></script> <script type=text/javascript
I've got a table which looks like this: <table id=display> <tr class=trigger> <td>Info here</td>
I really need some quick tips here. I've got this VBScript script which sends
I've got this bit of JQUERY: <script> function initNav() { $('.nav tr table td
How do I execute an output piped from a bash script? I got this
I've got a simple Visual Basic 2008 Express Edition form which looks like this:
I've got a download script which checks a couple of things and then streams
I got this script called rapidshare link checker v2 php by Bigfish At the
I've got this script on my website : $(document).ready(function() { function filterPath(string) { return
I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my

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.