我在wordpress(分页系统)的数据库中创建了一个新表

发布于 2024-09-26 17:04:41 字数 643 浏览 0 评论 0原文

我在wordpress的数据库中创建了一个新表。我还创建了一个新的模板页面来查看新表中的记录,但我想为此数据创建系统分页..

这是我的代码

global $wpdb;
$querystr = "SELECT * FROM wp_hotel WHERE id_city = ".$_GET['city-id'];
$pageposts = $wpdb->get_results($querystr);
if ($pageposts): ?>
<div class="list_hotels">
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="hotel">
<?php echo 'Hotel Name:'.$post->name-hotel; ?><br />
</div>
<?php endforeach; ?>
</div>
  <?php else : ?>
<p><?php _e('No Hotel in this city  ..'); ?></p>

<?php endif; ?>

I created a new table in the database of wordpress. Also I create a new template page to view the records in the new table, but I want to create a system paging for this data ..

this is my code

global $wpdb;
$querystr = "SELECT * FROM wp_hotel WHERE id_city = ".$_GET['city-id'];
$pageposts = $wpdb->get_results($querystr);
if ($pageposts): ?>
<div class="list_hotels">
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="hotel">
<?php echo 'Hotel Name:'.$post->name-hotel; ?><br />
</div>
<?php endforeach; ?>
</div>
  <?php else : ?>
<p><?php _e('No Hotel in this city  ..'); ?></p>

<?php endif; ?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很坚强 2024-10-03 17:04:41

我建议通过在末尾添加 LIMIT 来通过 mysql 查询实现分页。 LIMIT 采用两个整数,第一个指的是偏移量(即要跳过的记录数),第二个指的是要显示的记录数。例如,您的查询将是:

$pageoffset = $_GET['page'] * 10;
$querystr = "SELECT * FROM wp_hotel WHERE id_city = ".$_GET['city-id'] . " LIMIT ". $pageoffset .", 10";

然后在页面底部的页面链接上,您通过 url 传递您想要访问的页面。您还可以通过检查当前页面链接是否与 url 中设置的页面匹配来使当前页面链接变灰。

有道理吗?

埃文

I would recommend implementing paging through the mysql query by adding LIMIT to the end. LIMIT takes two integers, the first of which refers to the offset (that is how many records to skip) and the second to how many records to display. So for example your query would be:

$pageoffset = $_GET['page'] * 10;
$querystr = "SELECT * FROM wp_hotel WHERE id_city = ".$_GET['city-id'] . " LIMIT ". $pageoffset .", 10";

Then on the page links at the bottom of the page you pass through what page you want to go to through the url. You could also grey out the current page link by checking if it matches the page set in the url.

Make sense?

Evan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文