投稿 评论 顶部

小程序实现伪静态分页

佚名 网络安全

注 : 数据的话随便 ? ? 做伪静态需要先配置window可接window如何实现伪静态linux可接linux如何实现伪静态

页面名称叫:boke.php(代码下)

<?phpheader("content-type:text/html;charset=utf-8");$con = mysqli_connect('127.0.0.1','root','root','book');//连接数据库$con->set_charset('utf8');if (mysqli_connect_errno($con))//判断是否连接上数据库{    echo "连接 MySQL 失败: " . mysqli_connect_error();}//查询总条数$sql1 = "select count(*) as num from csdn";$res1 = mysqli_query($con,$sql1);$count = mysqli_fetch_assoc($res1);$count_num = $count['num'];//每页显示条数$num = 5;//总页码$page_count = ceil($count_num/$num);$p=empty($_GET['id'])?1:$_GET['id'];if($p<1){    $p=1;}elseif($p>$page_count){    $p=$page_count;}//偏移量$page_num = ($p-1)*$num;//查询所有数据$sql = "select * from csdn limit $page_num,$num";$res = mysqli_query($con,$sql);while($arr = mysqli_fetch_assoc($res)){    $data[]=$arr;}?><h3>erdan的博客</h3><table border="1">    <tr>        <td>blog_ID</td>        <td>blog_title</td>        <td>blog_author</td>        <td>blog_content</td>        <td>blog_url</td>        <td>blog_hot</td>        <td>blog_ctime</td>    </tr>    <?php foreach($data as $k => $v){?>        <tr>            <td><?php echo $v['id'];?></td>            <td><?php echo $v['b_tilte'];?></td>            <td><?php echo $v['b_author'];?></td>            <td><?php echo htmlspecialchars_decode($v['b_content']); ?></td>            <td><a href="<?php echo $v['b_url'];?>" target="_blank"><?php echo $v['b_url'];?></a></td>            <td><?php echo $v['b_number'];?></td>            <td><?php echo $v['b_time'];?></td>        </tr>    <?php }?></table></br><?php for($p=1;$p<=$page_count;$p++){ ?>    <a href="boke_csdn_<?php echo $p;?>.html"><?php echo $p; ?></a>//跳转时的路径重点html形式<?php    } ?>

.htaccess文件的代码

RewriteEngine onRewriteRule ^boke_csdn_(.*).html$ boke.php?id=$1

.htaccess文件必须和boke.php文件同级


htmlspecialchars_decode()函数是将储存时用的htmlspecialchars()函数变后的数据转回来