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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:27:02+00:00 2026-06-16T13:27:02+00:00

I have a table chart. Lets say 5 by 5. I run a loop

  • 0

I have a table chart. Lets say 5 by 5. I run a loop such as

<table>
    <tbody>
     <?php for ($i = 0; $i < 5; $i += 5) {
           echo "<tr>
              <td>one box</td>
              <td>one two</td>
              <td>one three</td>
              <td>one four</td>
           <tr>";
      }?>
     </tbody>
</table>

It creates a table such as

 |      |      |      |      |       |
 -------------------------------------
 |      |      |      |      |       |
 -------------------------------------
 |      |      |      |      |       |
 -------------------------------------
 |      |      |      |      |       |
 -------------------------------------
 |      |      |      |      |       |
 -------------------------------------

Now I have mysql data I load for my purposes and I need it to put the data in respectively so the table looks like

 |      |      |      |      |       |
 -------------------------------------
 |      |      |      |      |       |
 -------------------------------------
 |      | Res 1|      |      |       |
 -------------------------------------
 |      |      |      | Res 3|       |
 -------------------------------------
 |      |Res 4 |      |      |  Res 2|
 -------------------------------------

How would I do this? I have 50 results and need to fill the results into the correct column and row. I need to do some sort of if(results[0-50][‘id’] == rowcolumnid) echo the results for the correct table while doing the for loop.


Edit: Here is my full code.

    <table id="schedule">
        <tbody>
            <?php
            $time = mktime(0, 0, 0, 1, 1);
            for ($i = 28800; $i < 62200; $i += 1800) { ?>
             <tr id="row<?php echo $i; ?>">
                <td id="hour">
                    <?php 
                    printf('%1$s',date('g:i a', $time + $i)); 
                    ?>
                </td>
                                    <td id="sunday"></td>
                                    <td id="monday"></td>
                                    <td id="tuesday"></td>
                                    <td id="thursday"></td>
                                    <td id="friday"></td>
                                    <td id="saturday"></td>
            </tr>
            <?php } ?>
        </tbody>
    </table>

My mysql results are in datetime format that I’m going to use to propogate the table.

Results:

ID| EVENT NAME | DATEOFEVENT
1 | event name | 2012-11-20 12:00:00
2 | event name | 2012-11-21 13:30:00
3 | event name | 2012-11-22 13:00:00
4 | event name | 2012-11-23 11:00:00
5 | event name | 2012-11-24 08:00:00

etc.

I can do a strtotime of the dates and a date command to match.

  • 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-16T13:27:03+00:00Added an answer on June 16, 2026 at 1:27 pm

    If you first fetch the data (or if it is sorted if you first fetch the first data), then you can just iterate over the data when you match the hour/time that you iterate over to draw the table.

    As an example, I’ve chosen to display only one column that represents 5 hours (1-5) of which some can be matched. Those that are matched, are stored in an array and made available as an iterator (ArrayIterator):

    $data = [3,5];
    $datas = new ArrayIterator($data);
    $datas->rewind();
    

    Matched hours are represented with 1, unmatched ones with 0:

    echo "+---+---+\n";
    
    foreach(range(1, 5) as $hour)
    {
        if ($hasData = ($datas->valid() and $datas->current() === $hour)) {
            $datas->next();
        }
        $hasData = (int) $hasData;
    
    
        echo "| $hour | $hasData |\n";
        echo "+---+---+\n";
    };
    

    Output:

    +---+---+
    | 1 | 0 |
    +---+---+
    | 2 | 0 |
    +---+---+
    | 3 | 1 |
    +---+---+
    | 4 | 0 |
    +---+---+
    | 5 | 1 |
    +---+---+
    

    This works perfectly if the data from the data is available as an iterator (often the case, for mysql_* you need to write you one) and if it is sorted.

    Even this is only a single list here, for a table this works actually equally because a table is just a different form of representing the data.

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

Sidebar

Related Questions

I have following scenario: Lets say we have two different webparts operating on the
I have a html table which has several rows - lets say 17 for
I have this table, which can be seen as a basic custom gantt chart:
I have following tables in MySQL.(I am using php/mysql) CREATE TABLE `hw_subjects` ( `id`
I need to develop an international website. Let's say I have a table called
I have a table which needs 2 fields. One will be a foreign key,
I have a table that looks like this: I have this same chart on
A Report can have multiple charts. The Chart table looks as follows: Chart --
I have two DataTables objects on a page, lets call them searchResultsTable and currentPortfolioTable.
Lets say I have a LineItem (from the over used Shopping Cart example) and

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.