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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:09:30+00:00 2026-05-15T09:09:30+00:00

Here is my code. <table border=1 style=width:800px> <?php $schedule_db = mysql_query(SELECT * FROM schedule

  • 0

Here is my code.

<table border="1" style="width:800px">
                <?php $schedule_db = mysql_query("SELECT * FROM schedule WHERE '00:00' is not null and '01:00' is not null and '02:00' is not null and '03:00' is not null and '04:00' is not null and '05:00' is not null and '06:00' is not null and '07:00' is not null and '08:00' is not null and '09:00' is not null and '10:00' is not null and '11:00' is not null and '12:00' is not null and '13:00' is not null and '14:00' is not null and '15:00' is not null and '16:00' is not null and '17:00' is not null and '18:00' is not null and '19:00' is not null and '20:00' is not null and '21:00' is not null and '22:00' is not null and '23:00' is not null") 
                or die(mysql_error()); ?>
                <form method="post" action="config_action.php">
                <?php while($schedule = mysql_fetch_array( $schedule_db )) { ?>
                    <tr><?php if(isset($schedule['00:00'])) { ?><td style="width:32px"><?php echo $schedule['00:00'] ?></td><?php } if(isset($schedule['02:00'])) { ?><td style="width:32px"><?php echo $schedule['02:00'] ?></td><?php } if(isset($schedule['03:00'])) { ?><td style="width:32px"><?php echo $schedule['03:00'] ?></td><?php } if(isset($schedule['04:00'])) { ?><td style="width:32px"><?php echo $schedule['04:00'] ?></td><?php } if(isset($schedule['05:00'])) { ?><td style="width:32px"><?php echo $schedule['05:00'] ?></td><?php } if(isset($schedule['06:00'])) { ?><td style="width:32px"><?php echo $schedule['06:00'] ?></td><?php } if(isset($schedule['07:00'])) { ?><td style="width:32px"><?php echo $schedule['07:00'] ?></td><?php } if(isset($schedule['08:00'])) { ?><td style="width:32px"><?php echo $schedule['08:00'] ?></td><?php } if(isset($schedule['09:00'])) { ?><td style="width:32px"><?php echo $schedule['09:00'] ?></td><?php } if(isset($schedule['10:00'])) { ?><td style="width:32px"><?php echo $schedule['10:00'] ?></td><?php } if(isset($schedule['11:00'])) { ?><td style="width:32px"><?php echo $schedule['11:00'] ?></td><?php } if(isset($schedule['12:00'])) { ?><td style="width:32px"><?php echo $schedule['12:00'] ?></td><?php } if(isset($schedule['13:00'])) { ?><td style="width:32px"><?php echo $schedule['13:00'] ?></td><?php } if(isset($schedule['14:00'])) { ?><td style="width:32px"><?php echo $schedule['14:00'] ?></td><?php } if(isset($schedule['15:00'])) { ?><td style="width:32px"><?php echo $schedule['15:00'] ?></td><?php } if(isset($schedule['16:00'])) { ?><td style="width:32px"><?php echo $schedule['16:00'] ?></td><?php } if(isset($schedule['17:00'])) { ?><td style="width:32px"><?php echo $schedule['18:00'] ?></td><?php } if(isset($schedule['19:00'])) { ?><td style="width:32px"><?php echo $schedule['19:00'] ?></td><?php } if(isset($schedule['20:00'])) { ?><td style="width:32px"><?php echo $schedule['20:00'] ?></td><?php } if(isset($schedule['21:00'])) { ?><td style="width:32px"><?php echo $schedule['21:00'] ?></td><?php } if(isset($schedule['22:00'])) { ?><td style="width:32px"><?php echo $schedule['22:00'] ?></td><?php } if(isset($schedule['23:00'])) { ?><td style="width:32px"><?php echo $schedule['23:00'] ?></td><?php } ?></tr>
                <?php } ?>
                </form>
</table>

What I want to do is a have a table header (just a row above all the other rows) that shows what time each column is but only if there is a value in the column.

I thought I code to something like:

<tr><?php if(isset($schedule['00:00'])) { ?><td style="width:32px">00:00</td><?php } if(isset($schedule['01:00'])) { ?><td style="width:32px">01:00</td><?php } ?> etc.

However because it is in a while loop, it will happen before every actual row, which isn’t what I want to happen, I just want it to happen once on the top.

How can I solve this problem? Is there something I could append to that to make it only loop once?

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-15T09:09:31+00:00Added an answer on May 15, 2026 at 9:09 am

    Then don’t output your rows within the while loop. Save all data into a var. And then if the var contains content, put out the headrow and after that the var containing all content-rows.

    EDIT

    Okay that’s the most ugly code I’ve ever written, you could probably use arrays and stuff to make the code much smaller. But this is the code-snippet to get an idea… Capture all rows. While doing that check each field if it is filled in. If so, than you will need a column for that in the headrow. We do that by setting data0 for example to true. After processing the whole data we check out each var and look if it is true. If so, than you print the column in the headrow. So in the end you see, that you ouput the table-tag, then the headrow-var, then the string with all formatted data and then the closing table-tag. So you get the basic idea. Store headrow and the other rows in seperate vars and put them out in the right order…

    // Get data from database-table...
    $schedule_db = mysql_query('...your query...') or die(mysql_error());
    
    $data0 = false;
    $data1 = false;
    $data2 = false;
    // reapeat this for all hours till 23...
    
    while($schedule = mysql_fetch_array($schedule_db))
    {
        if(isset($schedule['00:00']))
        {
            $data0 = true;
            $row = '<td style="width: 32px;">' . $schedule['00:00'] . '</td>';
        }
    
        // Reapeat this for every hour you need...
        if(isset($schedule['01:00']))
        {
            $data1 = true;
            $row .= '<td style="width: 32px;">' . $schedule['01:00'] . '</td>';
        }
    
        //...
    
        $rows .= $row;
    }
    
    $headrow = '<tr>';
    if($data0 === true)
        $headrow .= '<th>00:00</th>' 
    
    if($data1 === true)
        $headrow .= '<th>01:00</th>';
    
    // Repeat for all hours...
    
    
    $headrow = '</tr>';
    
    echo '<table>';
    echo $headrow;
    echo $rows;
    echo '</table>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 541k
  • Answers 541k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is DestinationTable perhaps data-bound at this point? Since DataTable issues… May 17, 2026 at 2:52 am
  • Editorial Team
    Editorial Team added an answer Query INFORMATION_SCHEMA database for this. http://dev.mysql.com/doc/refman/5.1/en/information-schema.html May 17, 2026 at 2:52 am
  • Editorial Team
    Editorial Team added an answer Have you attempted the Asp:Table? <asp:Table ID="myTable" runat="server" Width="100%"> <asp:TableRow>… May 17, 2026 at 2:52 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm using this code to populate a Table: <style type=text/css> table, td { border-color:
There's a div2 here that has transparency using a css style tag. However the
I'm not really sure what I need here but I want to position a
My code is : <asp:TreeView ID=TreeViewCategories runat=server ExpandDepth=0 Style=min-height: 200px; max-height: 500px; LineImagesFolder=~/TreeLineImages NodeIndent=0
I dynamically added rows to a table but it doesn't seem to take hover
Am not sure why I cannot access my Label control which was inside the
This code below works perfectly for all browsers except IE 7 or 8. <img
I have two divs, one on the left, and one on the right side
I'm trying to create a layout for my website and I'm stuck with this.
I'm trying to have text spans pop up on a hover pseudo-class for different

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.