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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:22:00+00:00 2026-06-13T09:22:00+00:00

I need to either have a masive select statement or multiple queries. I need

  • 0

I need to either have a masive select statement or multiple queries. I need to break down data into specific timeframes during the day. This one works great for the first interval, but after that I’m stumped. If I have multiple queries, I’m having trouble with my “mysql_fetch_array”, as to the syntax (using something like ‘else’ and going through them).

SELECT U.user_name,ROUND(SUM((TA.task_average*TC.completed)/60),2) AS equiv1, S.submit_date,
    SUM(TC.completed) AS ttasks1,
    FROM `summary` S
    JOIN users U ON U.user_id = S.user_id
    JOIN tasks TA ON TA.task_id = S.task_id
    JOIN tcompleted TC ON TC.tcompleted_id = S.tcompleted_id
    JOIN minutes M ON M.minutes_id = S.minutes_id
    WHERE DATE(submit_date) = curdate( )
      AND TIME(submit_date) BETWEEN '06:00:00' and '07:59:59'       
      GROUP BY U.user_name
    LIMIT 0 , 30

My fetch array ( I would need to have a bunch more, but how to I combine them?)

<?php
while($rows=mysql_fetch_array($result1)){

?>
  • 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-13T09:22:01+00:00Added an answer on June 13, 2026 at 9:22 am

    ok, given that you want the data across regular 2 hourly intervals, you could try something like this:

    SELECT FLOOR(hour(S.submit_date)/2)*2, U.user_name,ROUND(SUM((TA.task_average*TC.completed)/60),2) AS equiv1, S.submit_date
        SUM(TC.completed) AS ttasks1,
        FROM `summary` S
        JOIN users U ON U.user_id = S.user_id
        JOIN tasks TA ON TA.task_id = S.task_id
        JOIN tcompleted TC ON TC.tcompleted_id = S.tcompleted_id
        JOIN minutes M ON M.minutes_id = S.minutes_id
        WHERE DATE(submit_date) = curdate( )
          GROUP BY U.user_name, FLOOR(hour(S.submit_date)/2)
        LIMIT 0 , 30
    

    where FLOOR(hour(S.submit_date)/2)*2 will map each hour to the first (even) hour of every 2 and you can group by this value. ie.

    0, 1 -> 0
    2, 3 -> 2
    4, 5 -> 4
    etc...
    

    update with php included:

    some notes:

    • i’ve used mysqli
    • i’ve left joined the original query with an hours derived table to ensure there are no
      ‘gaps’ in the time intervals (assumed 6:00 – 20:00)
    • i’ve ordered by user, so we as we loop through the results we can print table cells for a given user and then print a new table row when the user changes.

    here’s the code:

    echo '<table border=1><tr><td></td>';
    for ($i=6; $i<=18; $i=$i+2) {
        echo '<td colspan=2>'.$i.' - '.($i+2).'</td>';
    }
    
    $mysqli = new mysqli('MY_HOST', 'MY_USER', 'MY_PASSWORD', 'MY_DATABASE');
    
    $sql = "
    SELECT user_name, IFNULL(equiv1,0) AS equiv1, IFNULL(ttasks1,0) AS ttasks1, hour
    FROM
    (
        SELECT 6 AS hour
        UNION SELECT 8
        UNION SELECT 10
        UNION SELECT 12
        UNION SELECT 14
        UNION SELECT 16
        UNION SELECT 18
    ) hours LEFT JOIN
    
    (
    SELECT FLOOR(hour(S.submit_date)/2)*2 as task_hour, U.user_name, ROUND(SUM((TA.task_average*TC.completed)/60),2) AS equiv1, S.submit_date
        SUM(TC.completed) AS ttasks1
        FROM `summary` S
        JOIN users U ON U.user_id = S.user_id
        JOIN tasks TA ON TA.task_id = S.task_id
        JOIN tcompleted TC ON TC.tcompleted_id = S.tcompleted_id
        JOIN minutes M ON M.minutes_id = S.minutes_id
        WHERE DATE(submit_date) = curdate( )
          GROUP BY U.user_name, FLOOR(hour(S.submit_date)/2)
        LIMIT 0 , 30
    ) task_summary
    ON hours.hour = task_summary.task_hour
    ORDER BY user_name, hour
    ";
    
    $result = $mysqli->query($sql);
    
    $user_name = '';
    while ($row = $result->fetch_assoc()) {
        if ($user_name <> $row['user_name']){
            echo '</tr><tr><td>'.$row['user_name'].'</td>'; //start a new row if user changes
            $user_name = $row['user_name']; //update user variable for checking on next iteration
        }
        echo '<td>'.$row['equiv1'].'</td>';
        echo '<td>'.$row['ttasks1'].'</td>';
    }
    
    echo '</tr><table>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to either have multiple script managers on a page or
i have a mixed aspx/MVC webapp project and need to rewrite incoming URL's either
I need ruby to either take the value from an f.select or an f.text_field
I need to read the data from a file that can be either comma
I need to have either the only country viewed or the default country to
I think I have now a good grasp of why you need to either
I have a UDF that queries data out of a table. The table, however,
this is a homework which I already did, I just need either confirmation if
I need to either bring front browser window if it is already running or
I need to capture either \d+\.\d+ or \d+ but nothing else. For instance ,

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.