gpt4 book ai didi

php - 分页我的 Html/Php/MySql 脚本

转载 作者:行者123 更新时间:2023-12-01 00:12:07 26 4
gpt4 key购买 nike

我如何对该脚本进行分页以在一页上显示 5 行,在另一页上显示 5 行,依此类推。我已经为此尝试了教程和更多内容,但仍然无法理解。

以下是我的代码:

<?php require "manybr.htm" ?>
<style>
<?php require "styles.css" ?>
</style>
<?php

$host="XXXXX"; // Host name
$username="XXXX"; // Mysql username
$password="XXXXX"; // Mysql password
$db_name="XXXX"; // Database name
$tbl_name="tylted"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// select record from mysql
$sql="SELECT * FROM $tbl_name order by id desc";
$result=mysql_query($sql);
?>
<table background='images/view.png' width='50%' align='center'>
<tr>
<th align='center'>Group</th><th align='center'>Submition By</th><th align='center'>Submition On</th><th align='center'>ScreenName</th><th align='center'>Password</th><th align='center'>Does This Work?</th><th align='center'>Vote</th>
</tr>
<tr>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td background='transparent' align='center'><b><a href="http://aol.cellufun.com/p/grp/grp.asp?v=??&grp=<? echo $rows['group']; ?>">{<? echo $rows ['group']; ?>}</a> </b></td>
<td background='transparent' align='center'><b><a href="http://aol.cellufun.com/p/player.asp?v=&p=<? echo $rows['yname']; ?>"><? echo $rows['yname']; ?><a> </b></td>
<td background='transparent' align='center'><b><? echo $rows['date']; ?></b></td>
<td background='transparent' align='center'><b><? echo $rows['username']; ?></b></td>
<td background='transparent' align='center'><b><? echo $rows['password']; ?></b></td>
<td background='transparent' align='center'><b><? echo $rows['works']; ?>% Yes <font color='transparent'>||||</font>&nbsp; <? echo $rows['dworks']; ?>% No</b></td>
<td background='transpatent' align='center'><b><a href='works.php?id=<? echo $rows['id']; ?>'><img src='images/ThumbsUp.png' height='30' width='30'></a>&nbsp;&nbsp;&nbsp;<a href='dworks.php?id=<? echo $rows['id']; ?>'><img src='images/ThumbsDown.png' height='30' width='30'></a>

</td>
</tr>

<?php
// close while loop
}
?>

<?php
// close connection;
mysql_close();
?>
</table>

我已将 LIMIT 0 , 5 添加到我的查询中,现在显示 5。我如何处理带有第 2 页链接的部分?

我还不知道 MySqliPDO。我很快就会学会,所以请不要发表评论。我很快会将我的内联代码移动到 CSS 中,但现在还没有。我需要先让它工作。

<?php

$host="XXX"; // Host name
$username="XXX"; // Mysql username
$password="XXX"; // Mysql password
$db_name="XXX"; // Database name
$tbl_name="tylted"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


// select record from mysql
$offset=$_GET['p'];
$sql="SELECT * FROM $tbl_name order by id desc LIMIT 4 OFFSET ".$offset;
$result=mysql_query($sql);
?>
<table background='images/subbg.png' width='70%' align='center'>
<tr><th><?php require "links.php" ?></th></tr>
<tr>
<th align='center'>Group</th><th align='center'>Submition By</th><th align='center'>Submition On</th><th align='center'>ScreenName</th><th align='center'>Password</th><th align='center'>Does This Work?</th><th align='center'>Vote</th>
</tr>
<tr>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='lime' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
<th align='center'>
<hr color='gold' width='100%'/>
</th>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td background='transparent' align='center'><b><a href="http://aol.cellufun.com/p/player.asp?v=&p=<? echo $rows['yname']; ?>"><? echo $rows['yname']; ?><a> </b></td>
<td background='transparent' align='center'><b><? echo $rows['date']; ?></b></td>
<td background='transparent' align='center'><b><? echo $rows['username']; ?></b></td>
<td background='transparent' align='center'><b><? echo $rows['password']; ?></b></td>
<td background='transparent' align='center'><b><? echo $rows['works']; ?>% Yes <font color='transparent'>||||</font>&nbsp; <? echo $rows['dworks']; ?>% No</b></td>
<td background='transpatent' align='center'><b><a href='works.php?id=<? echo $rows['id']; ?>'><img src='images/ThumbsUp.png' height='30' width='30'> </a>&nbsp;&nbsp;&nbsp;<a href='dworks.php?id=<? echo $rows['id']; ?>'><img src='images/ThumbsDown.png' height='30' width='30'></a>

</td>
</tr>

<?php
// close while loop
}
?>

</table>

^^^^ 更新上面的 bozdoz

最佳答案

在您的 SQL 查询中附加 LIMIT 5 OFFSET 1 以在第一页显示 5 个结果。增加下一页的偏移值。

示例:

OFFSET 2 为您提供接下来的 5 个结果,依此类推...

要放置到下一页的链接,您可以尝试将偏移值设置为变量。

OFFSET $offset 其中 $offset 在 php 中递增。

index.php

<?php
if(isset($_GET['p'])){
if(is_numeric($_GET['p']))
$offset=$_GET['p'];
else
$offset=1;
}
else
$offset=1;

$sql="SELECT * FROM $tbl_name order by id desc LIMIT 5 OFFSET ".$offset;
$result=mysql_query($sql);
?>

然后是链接

<a href='index.php?p=2'>2</a>

那应该显示 2 页等等你可以做到

关于php - 分页我的 Html/Php/MySql 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14064713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com