jmr3460 Posted December 27, 2009 Share Posted December 27, 2009 Hello All, I have a calendar that I am adding edit capabilities to. I am using cookies to give user that ability. I set the cookie expiration to the date of the event. I now have run into an issue that if the same user adds another event that is one month or more before the first event then the second cookie's expiration is changed to the second date. The possibly is that 3 or 4 or 5 event dates could be added by the same user. I can call all of these dates from the table, is there a function that selects the greatest value in an array or something like that? Quote Link to comment Share on other sites More sharing options...
laffin Posted December 27, 2009 Share Posted December 27, 2009 I would avoid cookies for any mid/long term storage, as many users will do housekeeping or use different computers. I would store them into a db instead. Quote Link to comment Share on other sites More sharing options...
jmr3460 Posted December 27, 2009 Author Share Posted December 27, 2009 I guess I should have looked a little longer. I found the max(). I am going to retrieve the dates and convert to unix then try putting them into the max array. I hope this works. Quote Link to comment Share on other sites More sharing options...
jmr3460 Posted December 27, 2009 Author Share Posted December 27, 2009 Hey it worked. About the cookie thing. This calendar has only about 20 or so events in the future. I am just giving the users of this calendar an option to be able to edit their own events. I have warned them about having to accept cookies and only being able to edit from the computer they added the event from. If the calendar becomes more busy in the future I will use mysql to allow users to login and edit. Another reason that I am using cookies are that some of these people will not add events if they have to work for it. This is how I solved my problem with my cookies: <?php $email = $_COOKIE['email']; $connection = mysql_connect("localhost", "user", "pw") or trigger_error(mysql_error()); $db_name = "arscnaor_calendar"; $db = mysql_select_db($db_name, $connection) or trigger_error(mysql_error()); //This is the time function to find the greatest time for any $email $sql = "SELECT date FROM calendar WHERE email = '$email' AND first_day = 1"; $query = mysql_query($sql) or trigger_error(mysql_error()); while($result = mysql_fetch_array($query)){ $times = strtotime($result['date']); } $max = max(array($times)); setcookie("test", $email, $max, "/", ".site.org"); ?> If there is a faster or more efficient way I am more that willing to try it. Quote Link to comment 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.