0

i want to add next and previous links for my data table. how to write query to get data in next and prevous links data

<div>
   <a style="margin-left:5px;" href="#" class="previous">&laquo; Previous</a>
   <a style="margin-left:5px;" href="#" class="next">Next &raquo;</a>
</div>
$recordsPerPage = 20;

$totalPages = ceil($totalCount / $recordsPerPage);

$page = isset($_GET['page']) ? $_GET['page'] : 1;

$offset = ($page - 1) * $recordsPerPage;

$query = "SELECT * FROM history" . $whereClause . " LIMIT " .$recordsPerPage. "OFFSET " .$offset.";";

i am expecting to get data only 20 entries first when i click on next i want to show next 20 entries

lada
  • 263
  • 2
  • 8
  • The URL in the href of those buttons needs to contain the page parameter of the next or previous page, then. – ADyson Jun 08 '23 at 06:13
  • That's okay may I know how to get page data the query is not working. I checked with Echo am getting same 20 entries every time – lada Jun 08 '23 at 08:50
  • Presumably you are not setting the page value correctly then. We don't know what value you used for $_GET["page"] in your test. – ADyson Jun 08 '23 at 08:51
  • the offset is not working in cassandra – lada Jun 08 '23 at 08:52
  • oh I see. Sorry I missed that, I assumed it was mysql. You'll need to google what syntax can be used to get the same effect in Cassandra than, I am not familiar with that application personally. – ADyson Jun 08 '23 at 08:53
  • Maybe some answers from https://stackoverflow.com/questions/26757287/results-pagination-in-cassandra-cql or [similar results](https://www.google.com/search?q=cassandra+db+sql+offset) will be useful to you. – ADyson Jun 08 '23 at 08:54

1 Answers1

3

You'll need to call nextPage:

<?php
$cluster   = Cassandra::cluster()
               ->withContactPoints('127.0.0.1')
               ->build();
$session   = $cluster->connect("simplex");
$options   = array('page_size' => 5);
$rows      = $session->execute("SELECT * FROM paging_entries", $options);

while (true) {
    echo "entries in page: " . $rows->count() . "\n";

    foreach ($rows as $row) {
        echo "key: " . $row['key'] . ", value: " . $row['value'] . "\n";
    }

    if ($rows->isLastPage()) {
        break;
    }

    $rows = $rows->nextPage();
}

There are more examples here:

https://docs.datastax.com/en/developer/php-driver/1.3/features/result_paging/

stevenlacerda
  • 1,187
  • 2
  • 9
  • 21