【发布时间】:2012-12-28 15:39:39
【问题描述】:
如何分页此脚本以在一页上显示 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> <? 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> <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 页链接的部分?
我还不知道MySqli 或PDO。我很快就会学会,所以请不要发表这种评论。我将很快将我的内联代码移动到 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> <? 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> <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 更新
【问题讨论】:
-
请停止编辑我的 Q
-
协作编辑是一项功能。请查看网站常见问题解答。 stackoverflow.com/faq#editing -- 请努力使用正确的拼写、语法、大写和标点符号,您会发现其他人需要不那么频繁地编辑您的帖子。
-
在该示例中,您必须设置默认的 $offset。您还应该检查 $_GET['p'] 是否设置为 if(isset($_GET['p'])&&is_int($_GET['p'])){ ... }
-
@Charles 他们正在编辑以缩短我需要的内容,我感谢他们,但后来人们来回改变了它
-
我完全是 php 新手,老实说,我已经拥有这个脚本大约 3 周了,让它看起来像我想要的,并且像我希望我从编辑中学到更多东西一样设置,但现在我不知道是什么你说:c
标签: php html mysql pagination