php编写的简单页面跳转功能实现代码
程序员文章站
2022-06-22 21:00:30
不多说,直接上代码复制代码 代码如下://链接数据库'查询mysql_connect('localhost','username','userpwd')or die("数据...
不多说,直接上代码
//链接数据库'查询
mysql_connect('localhost','username','userpwd')or die("数据库链接失败".mysql_error());
mysql_select_db('库名');
mysql_query('set names utf8');
$sql1="select * from user ";
$query1=mysql_query($sql1);
$count=array();
while($row=mysql_fetch_assoc($query1)){
$count[]=$row;
}
$totalnews=count($count);
//判断page
if($_get['page']){
$page=$_get['page'];
}else{
$page=1;
}
$start=($page-1)*$newnum;
$sql="select * from user limit $start,$newnum";
$query=mysql_query($sql);
$ret=array();
while($row=mysql_fetch_assoc($query)){
$ret[]=$row;
}
?>
//表格样式
<div id="wrap" style="width:100%;height:100%; ">
<table border="1px"; style="border-collapse:collapse; border:1px solid #000; width:100%;height:100%">
<?php foreach ($ret as $key=>$value){ ?>
<tr>
<td><?php echo $value['id'] ?></td>
<td><?php echo $value['username'] ?></td>
<td><?php echo $value['pwd'] ?></td>
<td>删除|修改</td>
</tr>
<?php } ?>
<tr >
//页面跳转
<td colspan="4" align="center"><a href="upload.php?page=1">首页</a> <a href="upload.php?page=<?php echo $lastpage ?>">上一页</a> <?php echo $page; ?>/<?php echo $pagenum; ?> <a href="upload.php?page=<?php echo $nextpage; ?>">下一页</a> <a href="upload.php?page=<?php echo $pagenum ?>">尾页</a><input type="text" name="text" /><input type="button" value="跳转" onclick="check(this)"/>
</td>
</tr>
</table>
</div>
复制代码 代码如下:
//链接数据库'查询
mysql_connect('localhost','username','userpwd')or die("数据库链接失败".mysql_error());
mysql_select_db('库名');
mysql_query('set names utf8');
$sql1="select * from user ";
$query1=mysql_query($sql1);
$count=array();
while($row=mysql_fetch_assoc($query1)){
$count[]=$row;
}
$totalnews=count($count);
//判断page
if($_get['page']){
$page=$_get['page'];
}else{
$page=1;
}
$start=($page-1)*$newnum;
$sql="select * from user limit $start,$newnum";
$query=mysql_query($sql);
$ret=array();
while($row=mysql_fetch_assoc($query)){
$ret[]=$row;
}
?>
//表格样式
<div id="wrap" style="width:100%;height:100%; ">
<table border="1px"; style="border-collapse:collapse; border:1px solid #000; width:100%;height:100%">
<?php foreach ($ret as $key=>$value){ ?>
<tr>
<td><?php echo $value['id'] ?></td>
<td><?php echo $value['username'] ?></td>
<td><?php echo $value['pwd'] ?></td>
<td>删除|修改</td>
</tr>
<?php } ?>
<tr >
//页面跳转
<td colspan="4" align="center"><a href="upload.php?page=1">首页</a> <a href="upload.php?page=<?php echo $lastpage ?>">上一页</a> <?php echo $page; ?>/<?php echo $pagenum; ?> <a href="upload.php?page=<?php echo $nextpage; ?>">下一页</a> <a href="upload.php?page=<?php echo $pagenum ?>">尾页</a><input type="text" name="text" /><input type="button" value="跳转" onclick="check(this)"/>
</td>
</tr>
</table>
</div>
上一篇: LNMP部署laravel以及xhprof安装使用教程
下一篇: PHP实现的链式队列结构示例