Mato Mato - 2 months ago 5
SQL Question

Change my WHERE query depend on what day it is

I wonder if its possible to use my $today in WHERE query.
If $today is Monday, i want my WHERE to be p650Wdat = 1 (1 stands for monday)
And and tuesday will be 2 and so on.

$today = date("l");
<?php
$today = date("l");
//Establish connection to database
$host = "randomtext";
$conn = myacc");
$query = " Select *
from P660F
where p660WDAT = $today
ORDER BY P660PRIO DESC";
?>

Answer

OK so you want to match Monday to 1 and Tuesday to 2 etc. Really you should have same values in table as variables for simplicity and clarity butyou can return the day name as an integer like so

<?php
$day_name = date("l");
$today = date('N', strtotime($day_name));
echo 'Today name is ' . $day_name .'<br>';
echo 'Today number is ' . $today;
?>

Then your query should work

Comments