I am trying to set up pagination where the questions and answers are from separate tables. If I don't echo $question->questions() nothing shows up.
AJAX: (I have created another function just like this for the answers)
function loadQuestion(question) {
$.ajax({
url: "question.php",
method: "POST",
data: {question:question},
success:function(data) {
$('#questions').html(data);
}
});
}
PHP:
public function question() {
$sql = "SELECT * FROM questions";
$stmt = $db->prepare($sql);
$stmt->execute();
$questionPerPage = 1;
$totalNumberOfQuestions = $stmt->rowCount();
$totalNumberOfQuestions = ceil($totalNumberOfQuestions /
$questionPerPage);
if(isset($_POST['question'])) {
$questionNo = $_POST['question'];
} else {
$questionNo = 1;
}
$thisPageQuestion = ($questionNo - 1) * $questionPerPage;
$sql = "SELECT * FROM questions LIMIT ".$thisPageQuestion. ',' .$questionPerPage. 'ORDER BY id ASC' ;
$stmt = $db->prepare($sql);
$stmt->execute();
$questions = $stmt->fetchAll();
$output = '';
foreach($questions as $question) {
echo "<h2>" .$question['question']."</h2>";
}
HTML:
<button class="previous" name="previous"><-Back</button>
<section id="questions">
</section>
<section id="answers">
</section>
<button type="submit" class="next" name="next">Next-></button>