CSS-Regex Posted February 11 Share Posted February 11 (edited) I don't know if I've got the MySQL statement right, when I don't have the LIMIT and OFFSET, it displays all the results, but need the LIMIT for pagination CREATE TABLE photos ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), date_taken DATE, caption VARCHAR(255), type VARCHAR(255) ); This is in my MySQL statement SELECT * FROM photos WHERE LIMIT :limit_page OFFSET :offset Is the reason for lack of results due to the lack of column names? If so, is there anyway I can display the lot, but only limited to the LIMIT statement? This is the MySQL version mysqlnd 8.0.30 Edited February 11 by CSS-Regex Quote Link to comment https://forums.phpfreaks.com/topic/317924-not-displaying-any-results-from-the-database/ Share on other sites More sharing options...
CSS-Regex Posted February 12 Author Share Posted February 12 Don't worry, I found the problem, and it wasn't the MySQL statement Quote Link to comment https://forums.phpfreaks.com/topic/317924-not-displaying-any-results-from-the-database/#findComment-1615265 Share on other sites More sharing options...
Solution gizmola Posted February 13 Solution Share Posted February 13 On 2/11/2024 at 4:18 PM, CSS-Regex said: Don't worry, I found the problem, and it wasn't the MySQL statement The SQL statement you had was definitely wrong. LIMIT constrains a result set, and is not a valid part of a WHERE clause. Whatever you might have fixed, you also must have fixed that issue. Quote Link to comment https://forums.phpfreaks.com/topic/317924-not-displaying-any-results-from-the-database/#findComment-1615352 Share on other sites More sharing options...
Strider64 Posted February 13 Share Posted February 13 Here's my query -> $sql = 'SELECT * FROM '. $this->table . ' WHERE page =:page AND category =:category ORDER BY id DESC, date_added DESC LIMIT :perPage OFFSET :blogOffset'; it might help? Quote Link to comment https://forums.phpfreaks.com/topic/317924-not-displaying-any-results-from-the-database/#findComment-1615380 Share on other sites More sharing options...
Barand Posted February 13 Share Posted February 13 Aside from the empty WHERE clause mentioned by @gizmola above, you may also have a problem with passing your limit and offset parameters. You don't show us the relevant connection and execution code, but If your PDO connection code does not set ATTR_EMULATE_PREPARES to false (the default is true) then you cannot pass the limit and offset as parameters in an array when executing. You can, however, pass them using bindParam() You should always set this attribute to false 1 Quote Link to comment https://forums.phpfreaks.com/topic/317924-not-displaying-any-results-from-the-database/#findComment-1615381 Share on other sites More sharing options...
CSS-Regex Posted February 17 Author Share Posted February 17 On 2/11/2024 at 11:51 PM, CSS-Regex said: SELECT * FROM photos WHERE LIMIT :limit_page OFFSET :offset Yeah, well this isn't correct, its this as defined in the MySQL manual SELECT * FROM photos LIMIT :offset, :limit_page Quote Link to comment https://forums.phpfreaks.com/topic/317924-not-displaying-any-results-from-the-database/#findComment-1615799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.