I am trying to run an SQL query in PHP that is supposed to return one row based on the following two fields:
- first_shown_date
- last_shown_date
I am trying to select the one row based on the following conditions:
last_shown_date= Todays date, if false then:first_shown_date= 0000-00-00, if false then:last_shown_datewith the oldest date, this will be default
The query i currently have is giving me the wrong row, as i have one row with last_shown_date set to todays date, so that is the row that should be shown, but the row that is actually being shown is the one with the oldest date in last_shown_date.
I cant seem to figure this one out, instead of it being an "OR", it would ideally function as an "IF ELSE" statement, so that if rule #1 fails, then choose the next, but if rule #1 is true, then use that one and not the next. I tried if statements and CASEs but they did not work as needed either.
Here is the code i have at the moment:
SELECT
`id`,
`content`
FROM `".USED_TBL."`
WHERE
`last_shown_date` = '$dateDB' OR (`last_shown_date` != '$dateDB' AND
`first_shown_date` = '0000-00-00' OR(`first_shown_date` != '0000-00-00' AND
`last_shown_date` < '$dateDB'))
AND `status` != 2
ORDER BY
`last_shown_date` ASC
LIMIT 1
Aucun commentaire:
Enregistrer un commentaire