2 Replies Latest reply on Apr 30, 2007 9:37 AM by Optikalefx

    Thinking outside the box

    Optikalefx Level 1
      for what im building, users can vote once each week. So their voting status changes each week. Not only that the table in a database that data is drawn from will change per week. I have a big if else statement for intervals for 10 weeks. (i.e 7 to 14 is week 1, 14 to 21 is week 2 ect. BUT, how do i change everyones voting status back to NO after each week. heres some code. (php)

      //this first part basically gets the week, and takes care of the fact that the day after 365 is 1, but it doenst matter in this
      //example since 10 weeks will never reach 365. but its there in case i set the begin date to 300 or whatever.
      $curDate = date('z');
      $reset = 106;
      if ($curDate >= 1 && $curDate < $reset) {
      $beginDate = "65";
      $curWeek = $curDate + $beginDate;
      } else {
      $beginDate = "106";
      $curWeek = $curDate - $beginDate;
      }
      if ($curWeek >= 7 && $curWeek < 14) {$table = "week1t" ; $table2 = "week1p";}
      else if ($curWeek >= 14 && $curWeek < 21) {$table = "week2t" ; $table2 = "week2p";}
      else if ($curWeek >= 21 && $curWeek < 28) {$table = "week3t" ; $table2 = "week3p";}
      else if ($curWeek >= 28 && $curWeek < 35) {$table = "week4t" ; $table2 = "week4p";}
      else if ($curWeek >= 35 && $curWeek < 42) {$table = "week5t" ; $table2 = "week5p";}
      else if ($curWeek >= 42 && $curWeek < 49) {$table = "week6t" ; $table2 = "week6p";}
      else if ($curWeek >= 49 && $curWeek < 56) {$table = "week7t" ; $table2 = "week7p";}
      else if ($curWeek >= 56 && $curWeek < 63) {$table = "week8t" ; $table2 = "week8p";}
      else if ($curWeek >= 63 && $curWeek < 70) {$table = "week9t" ; $table2 = "week9p";}
      else if ($curWeek >= 70 && $curWeek < 77) {$table = "week10t" ; $table2 = "week10p";}
      else if ($curWeek >= 77 && $curWeek < 84) {$table = "week11t" ; $table2 = "week11p";}
      else if ($curWeek >= 84 && $curWeek < 91) {$table = "week12t" ; $table2 = "week12p";}
      else if ($curWeek >= 91 && $curWeek < 98) {$table = "week13t" ; $table2 = "week13p";}

      //this is the code to reset everyones status back to NO.
      $sql3 = mysql_query("UPDATE users SET voted = 'no'");


      so...where the hell do i put that code. I cant put it in the if else becaus that means every time this script is run it sets the status to no. And it cant be an interval because that means any day of the week it will set it back to no, and it cant be a single day because multiple times a day will return this back to no. it cant be expected to run on the last day of the week because what if no one opens the page on that day.

      so you can see where im stuck. kudos to anyone who cant think this thru.
        • 1. Re: Thinking outside the box
          Level 7
          I think you're going about it wrong. Why not have a date field in the users
          table, call it lastVoteDate. Then when someone tries to vote compare today
          to the lastVoteDate... if less than a week has passed they can't vote.
          Otherwise, let them vote and place today's date into lastVoteDate.


          --
          Dave -
          Head Developer
          http://www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: Thinking outside the box
            Optikalefx Level 1
            the problem is, its not a week from each user, its an absolute week.

            lemme see if what your saying can be written out.
            user bob votes on day 2. so his lastVoteDate is 2 (2/365 days)
            his vote status is now 'yes'
            the end of the week is 7.
            user bob wants to vote again the date is 12
            so...he cant vote cuz his status is 'yes'

            so if i try, he goes to vote and it sees 12>7 (ah ha week 2) sets status to 'no' and now he votes and status is 'yes'. and lastVoteDate is now 12.

            so he tiries to vote and its day 13, it sees 13>7 (ah ha week 2) sets status to 'no' and now he votes and status is 'yes' and lastVoteDate is now 13. WRONG

            soo......what am i missing?