Home Next Button and show data one at a time
Reply: 2

Next Button and show data one at a time

Noel_Ed
1#
Noel_Ed Published in 2018-02-14 10:26:50Z

TYA , can someone help me , I want to show the id(PRIMARy/ AI) one at a time everytime I click the Next button. But in my code it just increment only and still show the previous number .

Here is the code:

<?php
    include 'dbh.php';

    $commentNewCount = $_POST['commentNewCount'];

    $sql = "SELECT * FROM comments LIMIT $commentNewCount";
    $result = mysqli_query($conn, $sql);
    if (mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            echo $row['id'];
        }
    } else {
        echo "There are number!";
    }
?>

Code in Js

$(document).ready(function() {
  var commentCount = 0;
  $("button").click(function() {
    commentCount = commentCount + 1;
    $("#comments").load("load-comments.php", {
      commentNewCount: commentCount
    });
  });
});
JOE LEE
2#
JOE LEE Reply to 2018-02-14 10:43:06Z
$sql = "SELECT * FROM comments LIMIT 1 OFFSET $commentNewCount";

** SQL injection attacks

Hamza Abdaoui
3#
Hamza Abdaoui Reply to 2018-02-14 10:57:59Z

Follow me with this :

If $commentNewCount = 5, your current query SELECT * FROM comments LIMIT 5 will return 5 rows.

But, what you want is only 1 row where the id = 5!

So, your query should be :

$sql = "SELECT * FROM comments WHERE id = ".$commentNewCount;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315129 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO