|
|
| |
|
PHP分页连接mysql数据库(纠正数据库乱码) | |
| 阅读 1507 次 更新时间:2020/2/11 | |
|
config.php
<?php // Check connection
?> //////////////////////////////////////////////////////////////////////////
$sql = "select * from liminyes limit ".($page-1) * 5 .",5 ";//查询语句,limit后的两个参数第一个是查询的起始位置,第二个是显示的数据条数
echo "<table border=1 cellpadding=5 cellspacing=0 align='center' width='100%'>"; echo "<tr> <td>id</td> <td>name</td> <td>sex</td> <td>sessssx</td> </tr>"; while ($rows=mysqli_fetch_assoc($result)){ echo"<tr>"; echo "<td>{$rows['id']}</td>"; echo "<td>{$rows['name']}</td>"; echo "<td>{$rows['dizhi']}</td>"; $utf8Str=mb_convert_encoding($rows['dizhi'],"windows-1252");//将mysql数据库里面的乱码转换正确 echo "<td>ss{$utf8Str}</td>";
echo "</tr>"; echo "</table>";//循环输出数据
$to_sql="SELECT COUNT(*)FROM liminyes"; $result= mysqli_query($conn,$to_sql); $row=mysqli_fetch_array($result); $count=$row[0]; $to_pages=ceil($count/5); if($page<=1){ echo "<a href='".$_SERVER['PHP_SELF']."?p=1'>上一页</a>"; echo "<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一页</a>"; } if ($page<$to_pages){ echo "<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一页</a>";
echo "<a href='".$_SERVER['PHP_SELF']."?p=".($to_pages)."'>下一页</a>"; }
| |
|
|
|