"days left" coding

Discussion in 'PHP' started by mdrobiul, Oct 24, 2009.

  1. #1
    ok guys. i'm coding the "days left" function. after following a application in a book I just made it. i'm not sure that I made the right coding. suppose ads will be deleted after 120 days automatically. so i need to show the days left and also code auto removal the ads after 120 days.

    $days_left = round($current_time_stamp - $ads_creation_timestamp/86400);

    Your ads will be deleted after $days_left

    or $days_left == 121 {delete from database}

    Am I right ??
     
    mdrobiul, Oct 24, 2009 IP
  2. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i have another question. which is correct $days_left == 120 {delete from database} or $days_left == 121 {delete from database}
     
    mdrobiul, Oct 24, 2009 IP
  3. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #3
    do you have all details about particular advertisement stored in database? like start date and end date or days?

    if yes, then we can help you with a query that will give you remaining days directly which you can as it is use in php to display days left.

    please share table structure if you do not have much idea about it.
     
    mastermunj, Oct 24, 2009 IP
  4. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    do you mean that you want to accomplish this task using mysql function ? Mainly I'm going to create tables but I don't have the idea or logic of doing this task. I did not develop that section yet. so any idea is fine for me and I move forward with that. If I store start date like 12-12-2009, how will you count next 120 days ? how will you make the end date ? how will I make the "days left" too?

    My code that is in my post, I think that it can accomplish this task. but I'm not sure.
     
    mdrobiul, Oct 24, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    there are 2 ways.

    1. store start date and end date - then it is merely comparing current date with end date to know days left.
    2. store start date and total days - then it becomes calculating days left based on days passed since start date deducted from the total days.

    You can keep all 3, start date - end date - total days to make things convenient.

    Keep simple rule, things which mysql can do better must be done at mysql and things which php can do better must be done at php level unless there is a rare exception.
     
    mastermunj, Oct 24, 2009 IP