Table wont paginate when i echo the table rows .. default per page is 5 but it shows unlimited rows
Table wont paginate when i echo the table rows .. default per page is 5 but it shows unlimited rows

<table class="data-table dt-init user-tnx" id="transactionsTable">
<thead>
<tr class="data-item data-head">
<th class="data-col dt-tnxno">Status / ID</th>
<th class="data-col">Description</th>
<th class="data-col">Amount</th>
<th class="data-col d-none d-sm-table-cell">Partner</th>
</tr>
</thead>
<tbody>
<?php
// Attempt select query execution
$sql = "SELECT * FROM transactions WHERE startedBy='$username' ";
if($result = $db->query($sql)){
if($result->rowCount() > 0){
while($row = $result->fetch()){
echo ' <tr class="data-item"> ' ;
echo '<td class="data-col dt-tnxno">' ;
echo '
' ;
echo '</td>' ;
echo '<td class="data-col dt-token">' . $row['transactionType'] . '<span class="sub sub-symbol">I am the'.' ' . $row['role'] .'</span></td>' ;
echo '<td class="data-col dt-token">' . $row['transactionCurrency'] . ' ' . $row['price'] .'<span class="sub sub-symbol">$ 612.54</span></td>' ;
echo '<td class="data-col d-none d-sm-table-cell "><span class="lead token-amount">' . $email . '</span><span class="sub sub-symbol">TWZ</span></td>' ;
echo '<td class="data-col text-right"> ';
echo '
- ';
echo '
- Chat Now ' ; echo '
- '; echo '
';
echo '
- ';
echo '
- Chat Now '; echo '
- ' ; echo '
';
echo ' </td>' ;
echo ' </tr> ';
}
unset($result);
} else{
echo "<p class='lead'><em>You have no transactions done yet, <a href='startescrow.php'>click here </a>to start your first transaction</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . $mysqli->error;
}
// Close connection
unset($db);
?>
</tbody>
</table>
This question has an accepted answers - jump to answer
Answers
Not sure about your code but generally if the Datatable features aren't available and all rows are shown then there is an error in the Javascript. Take a look at the browser's console for errors.
Kevin
If i remove the echo making the tr plain html (by duplicating a single row multiple times ) the table paginates as wanted but with the echo everything displays on one page.
here is my console attached. Molel
Its something specific with your code causing the error not Datatables. It would be pretty hard to debug without actually seeing it running. Please post a link to your page or a test case replicating the issue.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
You can follow the lines in the traceback of the error and maybe find the problem, like lines 178 and 175 of script.js.
Kevin
Thanks Kevin. i got it fixed. i forgot to close the table row in my php echo therefore having all the data displayed as one single row. all i had to do is </tr> after the last </td>. thanks alot for pointing out the console log issue. i just got them all fixed . thanks K