-2

I'm trying to create script where I have to use logic kind of update records created in the last seven days.

$Update_ratings_table = mysql_query(
    "update ratings set rating = '5,5,5,5,5,5,5,5,5,5' where pid= '765' AND Date = ?????????"
);

Date format is: YYYY-MM-DD.

How can I create query which can update only last seven days records every week starting Monday?

I cannot hard code date because I'll run script on daily basis where it should take ONLY last 7 days records automatically.

halfer
  • 19,824
  • 17
  • 99
  • 186
krish kim
  • 192
  • 4
  • 9
  • It seems like you want to do this in PHP. Do you want to get the last seven days starting on a Monday regardless of what day it is? If so, your first task is to write some PHP to determine the date of the previous Monday (or today if today is a Monday). Can you give that a go? It will be better for your learning process if you try, rather than have someone write it for you. – halfer Jun 18 '13 at 19:49
  • From there, you can then subtract seven days from that date, and you'll have the start and end of your seven-day period. From there, writing a loop to run this query will then be trivial. – halfer Jun 18 '13 at 19:50

1 Answers1

2

You could get the correct date with PHP DateTime:

$datetime = new DateTime("-7 days");
$sql_date = $datetime->format("Y-m-d H:i:s");

$Update_ratings_table = mysql_query("update ratings set rating = '5,5,5,5,5,5,5,5,5,5' where pid= '765' AND Date >= '$sql_date' ");