Reputation: 53
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?
Upvotes: 5
Views: 20628
Reputation: 4901
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
Upvotes: 5
Reputation: 425261
$sql = 'SELECT * FROM tb_event WHERE DATE(edate) >= DATE(NOW()) ORDER BY edate DESC LIMIT 2';
Note that the actual error you get is in how you are calling mysqli_error
in the error processing code. Fix this too.
Upvotes: 2