如何创建一组选项来选择每页帖子的数量以及在博客上查看的页面

发布于 2024-10-01 08:59:22 字数 1691 浏览 7 评论 0原文

这似乎是世界上最简单的事情,但我失败了,可能是因为数学。无论如何,我的情况是这样的:

在我的 PHP 编程课程中,我指定自己写一个包含所有普通花哨功能的博客。我已经走了很短的路,但已经遇到了一个问题,我确信这个问题已经解决了至少十几次,但我的谷歌魔力未能找到解决方案。

所以这就是我想要做的:我想在页面上有许多链接,让用户选择每个页面上显示的博客文章数量以及更改用户所在页面的链接。

这是我正在处理的页面,它是瑞典语的,但你明白了,链接位于底部:http://lamp.skola.skelleftea.se/~matste/elever/christian_l/blag/index.php

这是我写的代码到目前为止未能给出想要的结果:

$antal = $_GET[antal];
if (!isset($antal)){
    $antal = 1;
}

$sida = $_GET[sida];
if (!isset($sida)){
     $sida = 0;
}

/*Some HTML markup here*/

$start = ($sida * $antal);
$stop = ($sida * $antal) + $antal;
$sql = "SELECT * FROM `posts` ORDER BY `number` DESC LIMIT {$start},{$stop}";
$posts = mysql_query($sql);

/*The code that shows the fetched posts*/

$antalsVal = array(1, 3, 5, 10);
echo '<table class="right"> <tr>';
foreach ($antalsVal as $val){
    echo '<td style="padding:0.7em"> <a href="http://lamp.skola.skelleftea.se/~matste/elever/christian_l/blag/index.php?
    antal='. $val. '&sida='. $sida. '"> '. $val. ' </a></td>';
}
echo '<td> <h5>: Inlägg per sida</td></table>';

$sidoVal = array(1, 2, 3, 4, 5);
echo '<table class="left"> <tr> <td> <h5>Sida: </td>';
foreach ($sidoVal as $val){
    echo '<td style="padding:0.7em"> <a href="http://lamp.skola.skelleftea.se/~matste/elever/christian_l/blag/index.php
    ?antal='. $antal. '&sida='. $val. '"> '. $val. ' </a></td>';
}
echo '</table><br /><br /><br />';

/*Some ending markup*/

This seems to be the simplest thing in the world to do, yet I'm failing, probably because of math. Anyhow, my situation is this:

In my programming in PHP course I've assigned myself to do a blog with all the normal bells and whistles. I've come a short way but have already run into a problem which I'm sure has been solved at least a dozen times, but my Google mojo fails to find me a solution.

So here is what I want to do: I want to have a number of links on the page which lets the user choose the number of blog posts shown on each page along with links changing which page the user is on.

Here is the page I'm working on, it's in Swedish but you get the idea, the links are at the bottom: http://lamp.skola.skelleftea.se/~matste/elever/christian_l/blag/index.php

And this is the code that I have written this far which fails to give the wanted result:

$antal = $_GET[antal];
if (!isset($antal)){
    $antal = 1;
}

$sida = $_GET[sida];
if (!isset($sida)){
     $sida = 0;
}

/*Some HTML markup here*/

$start = ($sida * $antal);
$stop = ($sida * $antal) + $antal;
$sql = "SELECT * FROM `posts` ORDER BY `number` DESC LIMIT {$start},{$stop}";
$posts = mysql_query($sql);

/*The code that shows the fetched posts*/

$antalsVal = array(1, 3, 5, 10);
echo '<table class="right"> <tr>';
foreach ($antalsVal as $val){
    echo '<td style="padding:0.7em"> <a href="http://lamp.skola.skelleftea.se/~matste/elever/christian_l/blag/index.php?
    antal='. $val. '&sida='. $sida. '"> '. $val. ' </a></td>';
}
echo '<td> <h5>: Inlägg per sida</td></table>';

$sidoVal = array(1, 2, 3, 4, 5);
echo '<table class="left"> <tr> <td> <h5>Sida: </td>';
foreach ($sidoVal as $val){
    echo '<td style="padding:0.7em"> <a href="http://lamp.skola.skelleftea.se/~matste/elever/christian_l/blag/index.php
    ?antal='. $antal. '&sida='. $val. '"> '. $val. ' </a></td>';
}
echo '</table><br /><br /><br />';

/*Some ending markup*/

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

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

发布评论

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

评论(1

花桑 2024-10-08 08:59:22

这是未经测试的。它可能不正确,但是尝试一下。

如果未设置 $sida,请将其设置为 1。

Let $start = ($sida * $antal) - $antal

Let $stop = $sida * $安塔尔

This is untested. It might not be correct But try this.

If $sida is not set, set it to 1.

Let $start = ($sida * $antal) - $antal

Let $stop = $sida * $antal

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