php數(shù)據(jù)庫(kù)連接及分頁(yè)
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
<?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>編號(hào):{$row['id']}"; echo "<li>用戶:{$row['username']}"; echo "</td>"; echo "<td> 標(biāo)題:<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'>首頁(yè)</a> "; echo "<a href='message.php?curpage=".($curpage-1)."'>前頁(yè)</a> "; } if($curpage<$pages){ echo "<a href='message.php?curpage=".($curpage+1)."'>后頁(yè)</a> "; echo "<a href='message.php?curpage=$pages'>尾頁(yè)</a>  "; } echo "</div>"; } ?> 該文章在 2012/7/11 16:52:27 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |