php - How to create today, tomorrow and yesterday with MySQL -
first of have searched forum getting answer problem. creating weekly schedule php & mysql , problem can not figure out how setup case statement when actual day sunday , need set monday tomorrow. here simple mysql table week
fields: dayid(int,primary,auto-increment),day(varchar(25)) data: (1,'monday'),(2,'tuesday'),(3,'wednesday'),(4,'thursday'), (5,'friday'),(6,'saturday'),(7,'sunday');
here php code:
$today = date("n"); $query = "select *,case when dayid = '$today' 'today' when dayid = '$today' + 1 'tomorrow' when dayid = '$today' - 1 'yesterday' else day end days week "; $results = mysqli_query($link, $query); while ($r = mysqli_fetch_array($results)) { echo '<p>'.$r['days'].'</p>'; }
like wrote before can not figure out how set when $today = 7 (sunday) monday tomorrow , other way around when it´s monday says yesterday instead of sunday. can me solve this.
thank in advance!
you need use if
wrap around @ end of week:
case dayid when $today today when if($today = 7, 1, $today + 1) 'tomorrow' when if($today = 1, 7, $today - 1) 'yesterday' else day end days
Comments
Post a Comment