如何分页此脚本以在一页上显示 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