Reputation: 477
I have this php code to get data from database
<?php
require_once ("db.php");
$db = new MyDb();
if (isset($_POST['limit']) && isset($_POST['start'])) {
$start = $_POST["start"];
$limit = $_POST["limit"];
$query =<<<EOF
SELECT * FROM questions ORDER BY quiz_id DESC '$start', '$limit';
EOF;
$result = $db->query($query);
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
echo 'div class="quesbox">
<div class="questitle">
<h2>'.$row["question"].'</h2>
</div>
<div class="quesanswer">'.$row["answer"].'</div>
<div class="quesdatetime"><img src="images/questime.png" alt="export question">'.$row["date"].'</div>
</div>';
}
}
?>
But each time i run this block of code i get these errors
Warning: SQLite3::query(): Unable to prepare statement: 1, near "'0'": syntax error in C:\xampp\htdocs\xport\searchfetch.php on line 14
Fatal error: Call to a member function fetchArray() on a non-object in C:\xampp\htdocs\xport\searchfetch.php on line 16
I have tried all the possible ways i know to fix the issue by editing the query
statement but to no avail. Please where is the issue from. Any help would be appreciated.
Upvotes: 1
Views: 768
Reputation: 883
You forgot the LIMIT
$query =<<<EOF
SELECT * FROM questions ORDER BY quiz_id DESC LIMIT '$start', '$limit';
EOF;
Upvotes: 2