I have this
$sql = 'SELECT * FROM tb_event WHERE DATE(edate) >= DATE(NOW())';
$result = $conn->query($sql) or die(mysqli_error());
$news = $result->fetch_assoc();
which runs fine however when I change it to this
$sql = 'SELECT * FROM tb_event WHERE DATE(edate) >= DATE(NOW() LIMIT 2)';
I get this error message
Warning: mysqli_error() expects exactly 1 parameter, 0 given in /var/www/.../...php
Finally I would like to combine it with order by that is something like this
$sql = 'SELECT * FROM tb_event WHERE DATE(edate) >= DATE(NOW() LIMIT 2 ORDER BY DESC)';
what am I doing wrong?
You need to pull the limit clause out of the DATE() macro.
SELECT * FROM tb_event WHERE DATE(edate) >= DATE(NOW()) LIMIT 2
Also if you want to order you have to set a field, like
SELECT * FROM tb_event WHERE DATE(edate) >= DATE(NOW()) LIMIT 2 ORDER BY myField DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With