Jump to content

r00ttap

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

r00ttap's Achievements

Member

Member (2/5)

0

Reputation

  1. Wow... you are absolutely right! Also, I've realized the if statement is throwing it off. I changed $post to isset($date) and all seems to be well. Thanks a lot!
  2. Here is the full function if anyone has the time to read through it. The problem lies with these two lines: if($post) { if(in_array($fullDate1, $cancelDate)) { $checked = "checked"; } } and if($post) { if(in_array($fullDate2, $cancelDate)) { $checked = "checked"; } } <?php function showCalendar1($date) { global $cancelDate; //If no parameter is passed use the current date. if($date == null) $date = getDate(); $day = $date["mday"]; $month = $date["mon"]; $month_name = $date["month"]; $year = $date["year"]; $dateSelect = mysql_query("SELECT date FROM course_cancellations_dates WHERE id = '$_GET[id]'") or die(mysql_error()); $cancelDates = array(); while($r=mysql_fetch_assoc($dateSelect)) { $cancelDates[] = date("d", strtotime($r['date'])); } $this_month = getDate(mktime(0, 0, 0, $month, 1, $year)); $next_month = getDate(mktime(0, 0, 0, $month + 1, 1, $year)); //Find out when this month starts and ends. $first_week_day = $this_month["wday"]; $days_in_this_month = round(($next_month[0] - $this_month[0]) / (60 * 60 * 24)); $calendar_html = "<table style=\"width: 360px; height: 100%; border: 1px solid #CCC; border-collapse: collapse\">"; $calendar_html .= "<tr><td colspan=\"7\" align=\"center\" style=\"background: #EEEEEE\">" . $month_name . " " . $year . "</td></tr>"; $calendar_html .= "<tr><td align=\"center\" style=\"border: 1px solid #CCC; height: 30px; width: 60px;\">Sun</td> <td align=\"center\" style=\"border: 1px solid #CCC; height: 30px; width: 60px;\">Mon</td> <td align=\"center\" style=\"border: 1px solid #CCC; height: 30px; width: 60px;\">Tue</td> <td align=\"center\" style=\"border: 1px solid #CCC; height: 30px; width: 60px;\">Wed</td> <td align=\"center\" style=\"border: 1px solid #CCC; height: 30px; width: 60px;\">Thu</td> <td align=\"center\" style=\"border: 1px solid #CCC; height: 30px; width: 60px;\">Fri</td> <td align=\"center\" style=\"border: 1px solid #CCC; height: 30px; width: 60px;\">Sat</td></tr><tr>"; //Fill the first week of the month with the appropriate number of blanks. for($week_day = 0; $week_day < $first_week_day; $week_day++) { $calendar_html .= "<td style=\"border: 1px solid #CCC;\"> </td>"; } $week_day = $first_week_day; for($day_counter = 1; $day_counter <= $days_in_this_month; $day_counter++) { $week_day %= 7; if($week_day == 0) { $calendar_html .= "</tr><tr>"; } //Do something different for the current day. if($day == $day_counter) { $checked = ""; $fullDate1 = date("Y-m-$day_counter"); if(in_array($day_counter, $cancelDates)) { $checked = "checked"; } if($post) { if(in_array($fullDate1, $cancelDate)) { $checked = "checked"; } } $calendar_html .= "<td valign=\"top\" align=\"right\" style=\"background: #BFEFFF\"><b>" . $day_counter . " <br /><center><input type=\"checkbox\" name=\"cancelDate[]\" value=\"$fullDate1\" $checked /></center></b></td>"; } else { $checked = ""; $fullDate2 = date("Y-m-$day_counter"); if(in_array($day_counter, $cancelDates)) { $checked = "checked"; } if($post && in_array($fullDate2, $cancelDate)) { $checked = "checked"; } $calendar_html .= "<td valign=\"top\" align=\"right\" style=\"border: 1px solid #CCC\">" . $day_counter . " <br /><center><input type=\"checkbox\" name=\"cancelDate[]\" value=\"$fullDate2\" $checked /></center> </td>"; } $week_day++; } $calendar_html .= "</tr>"; $calendar_html .= "</table>"; return($calendar_html); } ?>
  3. $selectedDates are being pulled from the form. There is a checkbox for each day of the month. I didn't want to post the whole calendar function because it's quite a bit of code. Everything I posted is being done within the for loop. I forgot to mention that once I pulled just the day from the $selectedDates and used that to match against selected days it worked but since I'm adding another month I need a full date format.
  4. Is there something I should know about in_array and the way it handles date formats? Essentially I'm setting up form validation with a calendar and I want to create a sticky form so if you selected a date but forgot something else it will remember what you selected. I started out with code like this: $day_counter is being pulled from a loop that counts the days in the month and will return 01 - 31, etc. <?php $fullDate = date("Y-m-$day_counter"); $selectedDates = array(); if(in_array($fullDate, $selectedDates)) { $checked = "checked"; } ?> <input type="checkbox" name="selectedDates[]" value="$fullDate" $checked />
  5. I have a calendar I'm using as a function that people can select dates from to post messages and also echo those same dates when they go back and edit a message. It seems everything works fine except for the first 9 days. From day 10 and on the dates will echo fine. I can't figure this one out. Here is the code for the first week of the calendar: $today = getdate(); $firstDay = getdate(mktime(0,0,0,$today['mon'],1,$today['year'])); $lastDay = getdate(mktime(0,0,0,$today['mon']+1,0,$today['year'])); // Display the first calendar row with correct positioning echo '<tr>'; for($i=1;$i<$firstDay['wday'];$i++){ echo '<td class="calTd"></td>'; } for($i=$firstDay['wday'];$i<=7;$i++){ $actday++; if ($actday == $today['mday']) { $class = ' class="calActday"'; } else { $class = ' class="calTd"'; } $checked = ""; $findDate = date("Y-m-$actday"); $dateSelect = mysql_query("SELECT date FROM course_cancellations_dates WHERE id = '$_GET[id]'") or die(mysql_error()); $cancelDates = array(); while($r=mysql_fetch_assoc($dateSelect)) { $cancelDates[] = $r['date']; } if(in_array($findDate, $cancelDates)) { $checked = "checked"; } echo "<td$class>$actday<br><center><input type='checkbox' name='date[]' value='" // Continue on next line .date("Y-m-$actday"). "' $checked /></center></td>"; } echo '</tr>'; I'm basically trying to gather the canceled dates and set them as an array and then if the dates are in that array, make the checkbox for those dates checked. This same code works for the rest of the month but for some reason not the first 9 days. Does anyone see anything wrong here? Thanks for the help!
  6. Maybe I'm having a brain fart here but I can't seem to figure this one out. I have a ridiculous SQL query that is working as I need but the problem lies in how I want the information sorted. Here's the scenario; I have multiple records in two different SQL tables linked by id, messages and dates. There are multiple dates for each message. I want to only list each message once, not for each record I have. My SQL satement looks something like this: SELECT * FROM messages, messages_dates WHERE campus = 'Campus' AND messages.id = messages_dates.id AND CONCAT((SELECT MAX(date) FROM mesaages_dates WHERE messages.id = messages_dates.id),' ',end_time) >= NOW() ORDER by date, start_time This gives me exactly what I want, all messages that have a date greater than today are listed, after today they disappear. But I believe my problem lies in my PHP code. while($row = mysql_fetch_assoc($query)){ echo "$row[date] $row[message]" <br />; } This will list something similar to this: 2009-06-19 This is the same message 2009-06-22 This is the same message 2009-06-23 This is the same message 2009-06-25 This is the same message 2009-06-27 This is the same message 2009-06-28 This is the same message I only want one message listed however I still need all the dates so they can be posted in a "pop-up" persay. I ultimately want something like this: 2009-06-19 to 2009-09-28 This is the same message [click here for more info] And when you click the info it will list all the dates. My main question is, how do I only list one message per "id" without SQL's "LIMIT 1" and retaining all the dates? Should I go about this a different way?
  7. Okay, so if I wanted to check if a date was in that array I would use: if(in_array("2009-06-19", $dates)) { $checked = "checked"; } echo $checked; Why am I receiving this: Warning: in_array() [function.in-array]: Wrong datatype for second argument
  8. Actually I'm going to ask another question that relates to this one. How does one set a while loop results as an array? $dateSelect = "SELECT dates FROM dates_table"; cancelDates = array(); while($row=mysql_fetch_assoc($dateSelect)) I basically want the dates to be set as an array.
  9. How would I go about checking if a variable equals anything within an array. For instances: $array = ('2009-06-01', '2009-06-02', '2009-06-20', '2006-06-25'); $today = "2009-06-20"; if($today = $array) { echo "Today was found within the array"; } I know that won't work but it's what I'm looking to accomplish. Thanks!
  10. Actually the GROUP BY is exactly what a wanted. I must have spelled something wrong because it's working perfectly now. Thanks for you time and help kickstart!
  11. kickstart, This works, as well as my original statement but the problem is that it only pulls 1 record. I want it to pull everything that >= NOW(). So if the dates were: 2009-06-14 2009-06-15 2009-06-16 2009-06-17 2009-06-18 2009-06-19 It will show the message until the 19th, after the 19th it won't pull the messages anymore.
  12. I have two tables. One that holds these messages along with some other information and another table that holds the dates that belong to these messages. I'm trying to only pull the messages that are >= NOW() meaning anything older than today will not display. The first "version" of this app was only able to store one date, an end date. I originally pulled the messages with this syntax: SELECT * FROM messages WHERE campus = 'campus' AND CONCAT(date,' ',end_time) >= NOW() ORDER by date, start_time The table looked a little liked this (along with a date field that housed the date to displayed): +----+------------+----------+-------------------------------+-------------------------+-------------------------------------------+ | id | start_time | end_time | course_name | campus | message | +----+------------+----------+-------------------------------+-------------------------+-------------------------------------------+ | 11 | 10:00:00 | 12:00:00 | Some course name | Campus | Test message with additional information. | +----+------------+----------+-------------------------------+-------------------------+-------------------------------------------+ Well now I need MULTIPLE dates for these messages and had to create the second table that houses only the ID and the dates. +----+------------+ | id | date | +----+------------+ | 11 | 2009-06-15 | | 11 | 2009-06-16 | | 11 | 2009-06-17 | | 11 | 2009-06-18 | | 11 | 2009-06-19 | +----+------------+ I've been working with this new syntax to pull the messages that looks like this: SELECT * FROM messages, messages_dates WHERE campus = 'campus' AND messages.id = messages_dates.id AND CONCAT(date,' ',end_time) >= NOW() GROUP BY messages.id ORDER by date, start_time And it will only pull 1 record, not all of the dates listed. I know my problem is "date". What I'm asking here is how do I get the last or "MAX(date)" from the dates table so that I can only select messages that are greater than or equal today, anything older than today will not be shown.
×
×
  • 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.