phpmysql分页


$DB="ac_clientlog_db";
$PageSize=5;


$con=mysql_connect("172.16.8.16:3306", "ac", "ac123"); #mysqli_connect
if(!$con)
die('Error :Could not connect: '.mysql_error());


$dbselect=mysql_select_db($DB, $con) or die('Error: select db error : '.mysql_error());


$rs=mysql_query("select count(*) from ClientLogs") or die("Error: select count* error : ".mysql_error());
$myrow=mysql_fetch_array($rs);
$numrows=$myrow[0];
$pages=intval($numrows/$PageSize);
if($numrows%$PageSize)
$pages++;


if(isset($_GET['page']))
$page=intval($_GET['page']);
else
$page=1;


$offset=$PageSize*($page-1);


$result=mysql_query("select * from ClientLogs order by Time desc limit $offset, $PageSize");


echo "<ul id='titleui'>";
echo "<li class='l1'><h4>DateTime</h4></li>";
echo "<li class='l2'><h4>Type</h4></li>";
echo "<li class='l3'><h4>Log</h4></li>";
echo "<li class='l4'><h4>Stack</h4></li>";
echo "<li class='l5'><h4>Device</h4></li>";
echo "</ul>";


while($row=mysql_fetch_array($result))
{
echo "<ul onclick='ChouseRow(this)'>";
echo "<li class='l1'>".$row['Time']."</li>";
echo "<li class='l2'>".$row['Type']."</li>";
echo "<li class='l3'>".$row['Log']."</li>";
echo "<li class='l4'>".$row['Stack']."</li>";

$tmpStack=$row['Device'];
if(strlen($tmpStack) > 18)
$tmpStack=substr($tmpStack, 0, 17);
echo "<li class='l5'>".$tmpStack."<span class='mydetials' style='display:none'>".$row['Detial']."</span></li>";
echo "</ul>";
}
#mysql_query("delete from ClientLogs") or die("Error: delete tab failed ".mysql_error());
mysql_close($con);


echo "<div style='clear:both; text-align:center;'>共有".$pages."页(".$page."/".$pages.")";
for($i=1; $i<=$pages; $i++)
echo "<a href='display.php?page=".$i."'>[".$i."]</a>";
echo "</div>";


echo "\n\nfinish! ";
 ?>
  </div>


  <div id="ID_HideDiv">努力加载中...</div>
</body>
</html>



分页逻辑是直接抄 http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2005/1224/452.html 这里的,懒得写。


你可能感兴趣的:(phpmysql分页)