php编写简单的页面跳转功能

不多说,直接上。

 1 
//确保magic_quotes_gpc在php.ini中移开启
function CheckInput($value){
  //去除反斜杠
  if(get_magic_quotes_gpc){
    $value = stripslashes($value);
  }
  //检测是否为数字
  if(!is_numeric){
    $value = "'".mysql_real_escape_string($value)."'"
  }
  return $value;
}

//链接数据库'查询 2 mysql_connect('localhost','username','userpwd')or die("数据库链接失败".mysql_error()); 3 mysql_select_db('库名'); 4 mysql_query('set names utf8'); 5 $sql1="select * from user "; 6 $query1=mysql_query($sql1); 7 $count=array(); 8 while($row=mysql_fetch_assoc($query1)){ 9 $count[]=$row; 10 } 11 $totalnews=count($count); 12 //判断page 13 if($_GET['page']){ 14 $page=$_GET['page']; 15 }else{ 16 $page=1; 17 }
$newbum = CheckInput($page);
18 $start=CheckInput(($page-1)*$newnum); 19 $sql="select * from user limit $start,$newnum"; 20 $query=mysql_query($sql); 21 $ret=array(); 22 while($row=mysql_fetch_assoc($query)){ 23 $ret[]=$row; 24 } 25 ?> 26 //表格样式 27 <div id="wrap" style="width:100%;height:100%; "> 28 <table border="1px"; style="border-collapse:collapse; border:1px solid #000; width:100%;height:100%"> 29 <?php foreach ($ret as $key=>$value){ ?> 30 <tr> 31 <td><?php echo $value['id'] ?></td> 32 <td><?php echo $value['username'] ?></td> 33 <td><?php echo $value['pwd'] ?></td> 34 <td>删除|修改</td> 35 </tr> 36 <?php } ?> 37 <tr > 38 //页面跳转 39 <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)"/> 40 </td> 41 </tr> 42 </table> 43 </div>

按照页数跳转的没写完。就下课了,回来百度之后继续写。以后补上。经过能猫指正,这个容易被sql注入。。

 

 

你可能感兴趣的:(页面跳转)