424,301 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,301 IT Pros & Developers. It's quick & easy.

Limiting rows of table and appending rows.

P: 19
In this code I am getting posts from database in table, table displays posts in three columns, now I want to add some jQuery to limit the number of rows and add a button which on clicking appends few rows to table I am not a professional programmer may be something like slice should be used to limit number of rows.

Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT * FROM posts";
  2. $query = $db->prepare($sql);
  3. $query->execute();
  5. <table>
  6. <tr>
  7. <?php do { //horizontal looper?>
  8. <td>
  9. <div>id</div>          
  10. <div>title</div>
  11. <div>body</div>          
  12. <div>date</div>
  13. </td>
  14. <?php
  15. $row = $query->fetch(PDO::FETCH_ASSOC);
  16. if (!isset($nested_List)) {
  17. $nested_List= 1;
  18. }
  19. if (isset($row) && is_array($row) && $nested_List++%3==0) {
  20. echo "</tr><tr>";
  21. }
  22. } while ($row); //end horizontal looper 
  23. ?>
  24. </table>
Oct 26 '15 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,639
it depends if you want to fetch the complete table through PHP and (un)hide parts of it or if you want to dynamically append rows.

for the latter you will need to use AJAX, which tends to be a JavaScript question. additionally, if you limit the results in PHP, you’d do that in SQL using the LIMIT clause (there’s no point fetching thousands of rows when you want to only display ten)
Oct 27 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.