英文:
how to get per page data from cassandra db using php
问题
我想为我的数据表添加下一页和上一页的链接。
如何编写查询以获取下一页和上一页的数据?
<div>
<a style="margin-left:5px;" href="#" class="previous">&laquo; 上一页</a>
<a style="margin-left:5px;" href="#" class="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.";";
我希望在点击下一页时只获取前20条数据,然后显示下一批20条数据。
英文:
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
答案1
得分: 3
你需要调用nextPage:
$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();
}
这里有更多示例:
https://docs.datastax.com/en/developer/php-driver/1.3/features/result_paging/
英文:
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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论