php数据库连接及分页
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
<?php
$rowperpage=3; $row=mysql_fetch_assoc(mysql_query("select count(*) as c from messages")); $rows=$row['c']; $pages=ceil($rows/$rowperpage); $curpage=1; if(isset($_request('curpage'))){ $curpage=$_request['curpage']; $sql="select * from messages order by id desc limit ".($curpage-1)*$rowperpage.",$rowsperpage"; $result=mysql_query($sql) or die(mysql_error()); while($row=mysql_fetch_assoc($result)){ echo "<table width='90%' ><tr>"; echo "<td rowspan='2' width='25%'>"; echo "<li>编号:{$row['id']}"; echo "<li>用户:{$row['username']}"; echo "</td>"; echo "<td> 标题:<a href='modify.php?id={$row['id']}'>{$row['title']}</a></td>"; echo "</tr></table><br>"; } echo "<div>"; for($i=1;$i<=$pages;$i++){ echo "<a href='message.php?curpage=$i'>$i</a> "; } echo "<form name='form1' action='message.php' method='post'>"; echo "<select name=curpage onchange='document.form1.submit();'>"; for($i=1;$i<$pages;$i++){ if($i==$curpage) echo "<option selected>$i</option>"; else echo "<option>$i</option>"; } echo "</select>"; echo "</form>"; if($curpage>1){ echo "<a href='message.php?curpage=1'>首页</a> "; echo "<a href='message.php?curpage=".($curpage-1)."'>前页</a> "; } if($curpage<$pages){ echo "<a href='message.php?curpage=".($curpage+1)."'>后页</a> "; echo "<a href='message.php?curpage=$pages'>尾页</a>  "; } echo "</div>"; } ?> 该文章在 2012/7/11 16:52:27 编辑过 |
关键字查询
相关文章
正在查询... |