首先说明隔行换色的效果,需要用到tr:nth_child(odd);或者括号里的值是even,odd是从第一行开始隔一行,even是从第二行开始:
具体代码如下图案所示:
1 <style> 2 /*tr:nth-child(even){*/ 3 /*background: #cad9ea;*/ 4 /*}*/ 5 </style>
在数据库当中查询第几条开始和我们需要显示的数据只要几条;我们可以用到limin语句,具体代码如下:
1 $sql = "select * from movie limit $sum,$pageSize";
还有就是隐藏表单inupt以及他的值需要用到在他的类型里面加上type=“hidden”跨页面表单隐藏具体代码如下:
1 <input type="hidden" value="<?php echo $row['id'] ?>" name="id" readonly="readonly"/>
还有如何取得数据库当中有多少行数我们需要用到mysql_mun_rows;代码如下所示:
1 $sql = "select * from movie limit $sum,$pageSize"; 2 echo $sql; 3 $result = mysql_query($sql) or die(mysql_error()); 4 5 $sql1 = "select * from movie"; 6 $result1 = mysql_query($sql1) or die(mysql_error()); 7 8 $count = mysql_num_rows($result1);
对于怎么制作上下翻页和在输入框里输入要跳转到第几页的代码如下图所示:
1 <html> 2 <head> 3 <title></title> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> 5 <style> 6 /*tr:nth-child(even){*/ 7 /*background: #cad9ea;*/ 8 /*}*/ 9 </style> 10 11 <script> 12 function changeColor(){ 13 var trs = document.getElementsByTagName("tr"); 14 for(var i=0;i<trs.length;i++){ 15 if( i%2 == 0){ 16 trs[i].style.background="#cad9ea"; 17 } 18 } 19 } 20 21 // function getPageNum(obj){ 22 // if(!isNaN(obj)){ 23 // location.href = "list.php?page="+obj; 24 // }else{ 25 // location.href = "#"; 26 // } 27 // } 28 29 window.onload=changeColor; 30 31 </script> 32 </head> 33 34 35 36 <body> 37 <table style="width: 500px"> 38 <tr> 39 <td>序号</td> 40 <td>电影名称</td> 41 <td>主演</td> 42 <td>类型</td> 43 <td>操作</td> 44 </tr> 45 <?php 46 include("conn.php"); 47 $page = ""; 48 if(@$_GET['page']){ 49 $page = $_GET['page']; 50 }else{ 51 $page = 1; 52 } 53 54 $pageSize = 3; 55 $sum = ($page-1)*$pageSize; 56 57 $sql = "select * from movie limit $sum,$pageSize"; 58 echo $sql; 59 $result = mysql_query($sql) or die(mysql_error()); 60 61 $sql1 = "select * from movie"; 62 $result1 = mysql_query($sql1) or die(mysql_error()); 63 64 $count = mysql_num_rows($result1); 65 66 67 $n=0; 68 69 function swiftType($type){ 70 $t = ""; 71 switch($type){ 72 case 1: 73 $t = "爱情"; 74 break; 75 case 2: 76 $t = "科幻"; 77 break; 78 case 3: 79 $t = "恐怖"; 80 break; 81 } 82 83 return $t; 84 85 } 86 87 while($row = mysql_fetch_array($result)){ 88 ?> 89 <tr> 90 <td><?php echo $row['id'] ?></td> 91 <td><a href="detail.php?id=<?php echo $row['id'] ?>"> <?php echo $row['moviename'] ?> </a></td> 92 <td><?php echo $row['actor'] ?></td> 93 <td> 94 <?php 95 echo swiftType($row['type']); 96 ?> 97 </td> 98 <td><a href="">删除</a> </td> 99 </tr> 100 101 <?php 102 $n++; 103 } 104 105 mysql_close($conn); 106 ?> 107 108 </table> 109 110 <span>共有<?php echo $count ?> 部电影</span> 111 <span>共有<?php 112 $totalPage = $count % $pageSize == 0 ? intval($count / $pageSize) : intval($count / $pageSize) + 1; 113 echo $totalPage; 114 115 ?> 页</span> 116 117 <a href="list.php?page=<?php echo $page-1 ?>">上一页</a> 118 119 <?php 120 for($i=1;$i<=$totalPage;$i++){ 121 ?> 122 <a href="list.php?page=<?php echo $i ?>"><?php echo $i ?></a> 123 <?php 124 } 125 ?> 126 <a href="list.php?page=<?php if($page >= $totalPage){echo $totalPage;}else{echo $page+1;} ?>">下一页</a> 127 128 跳转到 <input type="text" name="page" maxlength="5" size="5" id="txt"/> 页 129 130 </body> 131 <script> 132 var t = document.getElementById("txt"); 133 t.onkeydown=function(e){ 134 135 var e = e || window.event; 136 var key = e.keyCode; 137 if(key == 13){ 138 location.href = "list.php?page="+ t.value; 139 } 140 } 141 142 </script> 143 </html>
1 <html> 2 <head> 3 <title></title> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/> 5 </head> 6 <?php 7 include("conn.php"); 8 if(@$_GET['id']){ 9 $id = $_GET['id']; 10 $sql = "select * from movie where id=$id"; 11 $r = mysql_query($sql); 12 $row = mysql_fetch_array($r); 13 } 14 ?> 15 <body> 16 <form action="update.php" method="post"> 17 <input type="hidden" value="<?php echo $row['id'] ?>" name="id" readonly="readonly"/> 18 电影名称: <input type="text" value="<?php echo $row['moviename'] ?>" name="moviename"/> <br/> 19 主 演: <input type="text" value="<?php echo $row['actor'] ?>" name="actor"/> <br/> 20 <input type="submit" name="submit" value="修改"/> 21 </form> 22 </body> 23 24 </html>