Jump to content

Question regarding displaying results using PHP & <br>?


Solarpitch

Recommended Posts

Hey,

 

The following snippet of code will print to screen a series of times from 7:00am up until 11:50am. It will print them horizontally across the screen like this...

 

07:00 am 07:10 am 07:20 am 07:30 am 07:40 am 07:50 am 08:00 am.... etc

 

What I would like the code to do is but a <br> after every hour set or drop to a new line like this...

 

07:00 am 07:10 am 07:20 am 07:30 am 07:40 am 07:50 am <br>

08:00 am 08:10 am 08:20 am 08:30 am <br>

09:00 am 09:10 am 09:20 am 09:30 am 09:40 am 09:50 am <br>... etc

 

 

I am not sure how to tell the code to do this.

 


$myinfo[0] = "<table><tr>";
        $last = 0;
for ($i = $st; $i <= $en; $i += $int) {
            $hour = date('G',$i); //24 hour format
            if($last && $last != $hour){ //new hour
              $myinfo[0] .= "</tr><tr>";
              $last = $hour;
            }
    $time = date('h:i a',$i);
            $time_2 = date('G:i',$i);
    //if NOT in the exclude array then add a value
    if( !in_array($time, $exclude) ) 
    {
	$myinfo[0] .= "<td>{$time}</td>";
    }
}

$myinfo[0] .= "</tr></table>";

Nah, there should be an easier way that restructuring the code to use a 2d array. I am currently using split to get the first part of each hour.. eg:

 

07, 08, 09

 

I just need to match these values against each other an say... When 07 != $temp Value ... go to new line. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.