1

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.

2
  • Please do a echo $query;. Obviously there is something wrong with the query. Commented Jun 15, 2017 at 13:38
  • This is the echo result SELECT * FROM questions ORDER BY quiz_id DESC '0', '7'; I am trying to seat a limit from which data would be gotten from the database of wihich 7 is the limit Commented Jun 15, 2017 at 13:41

1 Answer 1

2

You forgot the LIMIT

$query =<<<EOF
SELECT * FROM questions ORDER BY quiz_id DESC LIMIT '$start', '$limit';
EOF;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.