A
A
Anton2016-10-30 23:12:01
PHP
Anton, 2016-10-30 23:12:01

Why is sql query throwing an error?

Hello! I am writing a communication module between the administrator and the user, messages are stored in the database. Now I decided to add pagination to them, I wrote the following query to the database:

public function getAllMessages($data) {
 
$sql = $this->db->query("SELECT * FROM " . DB_PREFIX . "message WHERE status = 1 ORDER BY date_added DESC");
 
if (isset($data['start']) && isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
 
if ($data['limit'] < 1) {
$data['limit'] = 10;
} 
 
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
} 
 
$query = $this->db->query($sql);
 
return $query->rows;
}

but swears at an incorrectly composed request:
Unknown: Object of class stdClass could not be converted to string in /catalog/model/contact/message.php on line 28
Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0,10' at line 1
Error No: 1064 LIMIT 0,10 in /system/library/db/mysqli.php on line 40
Notice: Trying to get property of non-object in /catalog/model/contact/message.php on line 33

I can't figure out what could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question