MYSQL Select by this week with index -


user can see have uploaded in week. have below code in line:

is correct?

select *  images  userid = '$userid'    , uploadeddate >= curdate() - interval weekday(day) day     , uploadeddate < curdate() - interval weekday(day) day + interval 7 day  order uploadeddate desc 

i have create index (userid, uploadeddate) .

for original query work day needs in database you're querying (or set variable) , needs in mysql date '0000-00-00' or date time '0000-00-00 00:00:00' formats.

weekday() returns 0-6 date entered.

$first; //is earliest offset in range $last; //is latest offset in range  select * images userid = '$userid' , uploadeddate > curdate() - interval $first day , uploadeddate < curdate() - interval $last day order uploadeddate desc 

so query return results last week.

select * images userid = '$userid' , uploadeddate > curdate() - interval 14 day , uploadeddate < curdate() - interval 7 day order uploadeddate desc 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -