General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 1st, 2004, 12:17 AM
JY11 JY11 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 8 JY11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question comparing dates

I am trying to write a php page that displays events that are entered by a user. One of the fields for these entries is a date field that the user enters in a YYYY/MM/DD format. When I read the datebase, which is a mysql db, I'm trying to check that the date of the event has not passed. If it has already passed i'm trying to delete it from my database altogether. I'm a little lost on the date comparison as i've managed to do everything from deleting all the records in my DB to deleting none of them. Any help on this code would be a great help. Thanks. This is the code from my display page that I have so far.
PHP Code:
<?php
   
//open connection

  
$conn mysql_connect("localhost""root""irmdog18");

  
//select db

  
mysql_select_db("samplerestaurant_com"$conn);

  
//create sql 

  
$sql "select * from event order by event_date";

  
//execute sql

  
$result mysql_query($sql$conn
            or die(
mysql_error());


  
$curdate time();

  
//go through each row and display data

  
while ($newarray mysql_fetch_array($result))
    {

      
$id $newarray['id'];
      
$event_title $newarray['event_title'];
      
$event_date $newarray['event_date'];
      
$event_listing $newarray['event_listing'];
      
$event_poster $newarray['event_poster'];
      
$event_email $newarray['event_email'];
      
      if (
$curdate$event_date)      
        {      

     

              
$sqlz "delete from event
                      where event_date = '$event_date'"
;

              
//execute sql

             
$resultz mysql_query($sqlz$conn
                       or die(
mysql_error());


        }

      else

        {

         
          
          echo 
" <table>
                 <tr>
                 <td NOWRAP width ='200'>
                     <strong><font color ='red'>Event: </font></strong>$event_title<br>
                     <strong><font color ='blue'>Event Date:</font></strong>$event_date<br>
                     <strong><font color ='red'>Event Contact:</font></strong>$event_poster at  $event_email<br>
                 </td>
                 <td>
                     &nbsp;&nbsp;&nbsp;
                 </td>
                  <td NOWRAP valign ='top'>
                   <strong><font color ='blue'>Event Description:</font></strong>
                  </td>
                  <td width ='1000000'valign ='top'>
                      $event_listing
                  </td>
                 </tr>
                 </table>

                 <HR>

"
;


        }

     }
?>

Reply With Quote
  #2  
Old April 1st, 2004, 12:45 AM
crudesys crudesys is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: California
Posts: 25 crudesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hi. what i would do about that is:

instead of comparing the date using the PHP if statement,
i will delete the record using where clause in the sql statement
WHERE event_date < now()
if this doesnt do the trick, try
WHERE to_days(event_date) < to_days(now())

// comment about if ($curdate< $event_date) ... delete ...
this condition as i understand says: if today's date is before the event's date, delete that event record. this would delete the upcoming events and keep the past events.

i hope my idea works for you.

good luck

Reply With Quote
  #3  
Old April 1st, 2004, 01:11 PM
JY11 JY11 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 8 JY11 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

Awesome, everything is working great. Thanks so much for the help.

Reply With Quote
  #4  
Old April 1st, 2004, 08:24 PM
crudesys crudesys is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: California
Posts: 25 crudesys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
my pleasure being of some help to you. good luck

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > comparing dates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT