newbie69 Posted November 1, 2007 Share Posted November 1, 2007 As u can guess i'm a junior at php and there a issue with a sites thats really troubling me. Please visit www.optinum.co.za to get a idea. Please have a look at the right hand column where it says "Next webnar". Its list november 13 as the next webinar. This is fine. All the data for this gets read from a data file. And example of the data file: -------------------- 2007-10-30 Understand the difference between process flows 2007-11-01 image processing with Matlab 2007-11-13 MATLAB Fundamentals and Programming Techniques -contains other dates---- ----------------------- This way the script was supposed work : Read in the dates and event. Display the upcoming events. Dont display events in the past. The scripts does all of this well but, if I have an event thats today eg 2007-11-01, the site does not display the event on the day of the event. I want it to display the event on the day of the event. Right now on the site it was supposed to display the event 2007-11-01 but it doesnt. I hope i'm being clear below i have highlighted when i think the problem maybe. If someone can help me clarify this it would be greatly appreciated this is the snippet of code that controls that: //BUILD THE WEBINARS DATA case "webinars": //--- this whole case was changed by Peter Gatlik on 5 June 2007 echo "<table border=\"0\" cellpadding=\"0\" cellpadding=\"0\">\n"; //6/08/07 clients did not want to print table headings so tr commented out //echo "<tr>"; //$headers = str_replace("\"", "", $headers); //echo "<td class=\"header\">".$headers[0]."</td>"; //echo "<td class=\"header bordersolid\">".$headers[2]."</td>"; //echo "</tr>"; if($numDisplayRecords !== 0) { $numlines = $numDisplayRecords; } //--- Code added by Peter Gatlik 5 June 2007 $SortingARY = array (); if (is_array ($lines)) { for ($i = 1; $i < count ($lines); $i++) { $Entry = explode ($sep, $lines[$i]); if ($Entry[0] == "") { continue; } unset ($DateTemp); //--- format for Webinars.txt is 2007-05-20 for example $DateTemp = explode ("-", $Entry[0]); $TmpYear = $DateTemp[0]; $TmpMonth = $DateTemp[1]; if ($TmpMonth < 10) { $TmpMonth = "0".((int)$TmpMonth); } $TmpDay = $DateTemp[2]; if ($TmpDay < 10) { $TmpDay = "0".((int)$TmpDay); } if (in_array ($TmpDay, array ("", "00")) || in_array ($TmpMonth, array ("", "00")) || in_array ($TmpYear, array ("", "00"))) { continue; } [color=green] //--- exlude it if it's in the past if (time () > mktime (0, 0, 0, $TmpMonth, $TmpDay, $TmpYear)) { continue; }[/color] //--- create the array index to create the new array $Key = $TmpYear.$TmpMonth.$TmpDay; $Entry['DisplayDate'] = date ("d F Y", mktime(0,0,0, $TmpMonth, $TmpDay, $TmpYear)); $SortingARY[$Key][] = $Entry; } //--- by this point we have the array with keys using the date in Ymd form and we need to sort the array by key and then loop through and create one array $FinalARY = array (); ksort ($SortingARY); reset ($SortingARY); foreach ($SortingARY AS $Entries) { foreach ($Entries AS $Entry) { $FinalARY[] = $Entry; } } } for ($i = 0; $i < ($numlines - 1); $i++) { $Entry = $FinalARY[$i]; $Entry = str_replace ("\"", "", $Entry); if ($Entry['DisplayDate'] == "") { continue; } echo "<tr>"; echo "<td class=\"content\">".$Entry['DisplayDate']." </td>\n"; echo "<td class=\"content bordersolid\">".($Entry[2] == "" ? " " : "<a href=\"".$Entry[4]."\" title=\"".$Entry[2]."\" target=\"_blank\">".$Entry[2]."</a>")."</td>"; echo "</tr>\n"; } echo "</table>\n"; break; EDIT: Please use the [code][/code] tags when pasting code on the forums. Quote Link to comment https://forums.phpfreaks.com/topic/75620-solved-need-help-with-time-and-date-functions/ Share on other sites More sharing options...
Barand Posted November 1, 2007 Share Posted November 1, 2007 I think this is the culprit if (time () > mktime (0, 0, 0, $TmpMonth, $TmpDay, $TmpYear)) { continue; change to this to eliminate time of day from the comparison if (mktime (0,0,0) > mktime (0, 0, 0, $TmpMonth, $TmpDay, $TmpYear)) { continue; Quote Link to comment https://forums.phpfreaks.com/topic/75620-solved-need-help-with-time-and-date-functions/#findComment-382637 Share on other sites More sharing options...
newbie69 Posted November 2, 2007 Author Share Posted November 2, 2007 Hi Barand, I tried this and still doesnt seem to be working. It doesnt show the event on the day of event. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/75620-solved-need-help-with-time-and-date-functions/#findComment-383340 Share on other sites More sharing options...
newbie69 Posted November 2, 2007 Author Share Posted November 2, 2007 Actually it works! I modified a wrong section of the script! Sorry Thanks alot! Its really appreiciated ! Quote Link to comment https://forums.phpfreaks.com/topic/75620-solved-need-help-with-time-and-date-functions/#findComment-383345 Share on other sites More sharing options...
slipzst Posted January 25, 2008 Share Posted January 25, 2008 i have a problem in a sorting a date... first of all the date is in the text format.. the actual sort of the date is 14-APR-07, so how should i do to solved this problem...the display is on the php coding. so i have manage to list out the data but dont have the sequal of month itself...thank you Quote Link to comment https://forums.phpfreaks.com/topic/75620-solved-need-help-with-time-and-date-functions/#findComment-448581 Share on other sites More sharing options...
Barand Posted January 25, 2008 Share Posted January 25, 2008 try ... ORDER BY STR_TO_DATE(mydatecol, '%d-%b-%Y') But the best solution is to use the correct ISO date format (yyyy-mm-dd) in the first place Quote Link to comment https://forums.phpfreaks.com/topic/75620-solved-need-help-with-time-and-date-functions/#findComment-448683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.