Solarpitch Posted June 23, 2008 Share Posted June 23, 2008 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>"; Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/ Share on other sites More sharing options...
waynew Posted June 23, 2008 Share Posted June 23, 2008 Use a 2d array. Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/#findComment-572161 Share on other sites More sharing options...
Solarpitch Posted June 23, 2008 Author Share Posted June 23, 2008 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. Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/#findComment-572177 Share on other sites More sharing options...
Solarpitch Posted June 24, 2008 Author Share Posted June 24, 2008 Can anyone have a look at this please? I really need to get this working soon or I will be shot. Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/#findComment-573063 Share on other sites More sharing options...
waynew Posted June 24, 2008 Share Posted June 24, 2008 What if you searched each string or date for a certain number? If it meets an 8 for the first time, introduce a <br/> Probably not at all what you were looking for. Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/#findComment-573066 Share on other sites More sharing options...
Solarpitch Posted June 24, 2008 Author Share Posted June 24, 2008 I'm not sure if that is to be honest. I didnt think this would be so tricky lol Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/#findComment-573068 Share on other sites More sharing options...
waynew Posted June 24, 2008 Share Posted June 24, 2008 Sometimes its best to start from scratch and rethink the whole problem. Don't tie yourself into one solution. Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/#findComment-573070 Share on other sites More sharing options...
shelluk Posted June 24, 2008 Share Posted June 24, 2008 Check if it contains :00 using strstr, if so echo a break before echoing that time? Link to comment https://forums.phpfreaks.com/topic/111473-question-regarding-displaying-results-using-php/#findComment-573092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.