這篇文章給大家介紹的文章內容是關於php分頁和正則驗證的代碼實現,有很好的參考價值,希望可以協助到有需要的朋友。
分頁:
<?phpheader("Content-type:text/html;Charset=utf8");$link=mysqli_connect("localhost:3306","root","root","weektwo");if(!$link) echo "串連失敗的原因是:" . mysqli_connect_error();mysqli_query($link,"set names utf8"); $tiao=4; $sql="select count(*) from kao"; $res=mysqli_query($link,$sql); $zong=mysqli_fetch_assoc($res); $z=count($zong); $max=ceil($z/$tiao);if(!$_GET['page']){ $page=1;}else{ if($page<1){ $page=1; }elseif($page>$max){ $page=$max; }else{ $page=$_GET['page']; }}$ye=($page-1)*$tiao;$sql="select * from kao where limit ".$ye.",".$tiao;$a=mysqli_query($link,$sql);while($res=mysqli_fetch_assoc($a)){ $arr[]=$res;}// var_dump($arr);die;?><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title></head><body> <table border="1"> <tr> <td>編號</td> <td>姓名</td> <td>分類</td> <td>單價</td> <td>狀態</td> <td>庫存</td> <td>產地</td> </tr> <?php foreach($arr as $key => $v) {?> <tr> <td><?php echo $v['id']?></td> <td><?php echo $v['name']?></td> <td><?php echo $v['fen']?></td> <td><?php echo $v['dj']?></td> <td><?php echo $v['zhuang']?></td> <td><?php echo $v['kucun']?></td> <td><?php echo $v['chan']?></td> </tr> <?php }?> <a href="1.php?page=1">首頁</a> <a href="1.php?page=<?php echo $page-1;?>">上一頁</a> <a href="1.php?page=<?php echo $page+1;?>">下一頁</a> <a href="1.php?page=<?php echo $max;?>">尾頁</a> </table></body></html>
正則驗證:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>正則</title></head><body><form action="" onsubmit="fun()"> <table border="1"> <tr> <td>姓名</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>性別</td> <td> <input type="radio" name="sex">男 <input type="radio" name="sex">女 </td> <td width="200"><span></span></td> </tr> <tr> <td>密碼</td> <td><input type="text" id="xm"></td> <td width="200"><span></span></td> </tr> <tr> <td>確認密碼</td> <td><input type="text" id="xm"></td> <td width="200"><span></span></td> </tr> <tr> <td>郵箱</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>城市</td> <td> <select name="a4" id="o" onclick="fun1()"> <option value="">請選擇</option> <option value="0" >北京</option> <option value="1">上海</option> <option value="2">衡水</option> <option value="3">石家莊</option> </select> </td> <td width="200"><span></span></td> </tr> <tr> <td>手機號</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>有線電話號</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>社會安全號碼</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>QQ號</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td>自我介紹</td> <td><input type="text"></td> <td width="200"><span></span></td> </tr> <tr> <td><input type="submit" value="登入"></td> <td><input type="submit" value="重設"></td> </tr> </table> </form> <script> var inp = document.getElementsByTagName('input'); var sp = document.getElementsByTagName('span'); var o = document.getElementsByTagName('option'); var reg = /^[a-zA-Z][a-zA-Z0-9]{4,9}$/; var pass =/^[a-zA-Z0-9_]{6,}$/; var p=/^[0-9]+[a-zA-Z]{3,}$/; var emile =/^[a-zA-Z0-9]+@[a-zA-Z0-9](\.)(.net|cn){2,6}$/; var tel =/^1[5|8|3][0-9]{9}$/; var qq= /^[0-9]{8,11}$/; var t=/^[0-9][0-9][0-9]-[0-9]{8}$/; var shen=/^[0-9]{14,17}[0-9X]$/; var te=/^[0-9a-zA-Z_]{0,20}$/; var city=/^[0-9]$/; inp[0].onblur = function (){ //console.log(inp[0].value); if(!reg.test(inp[0].value)){ sp[0].innerText = "必須由5到10位元字或字母組成,不允許數字開頭"; }else{ sp[0].innerText= "√"; } } inp[3].onblur = function (){ if(!pass.test(inp[3].value)){ sp[2].innerText = "密碼必須在6位以上"; }else{ sp[2].innerText= "√"; } } inp[3].onblur = function (){ if(!pass.test(inp[3].value)){ sp[2].innerText="密碼必須6位以上"; }else{ sp[2].innerText="√"; } } inp[4].onblur = function (){ if(inp[3].value!=inp[4].value){ sp[3].innerText = "確認密碼和密碼必須一致"; }else{ sp[3].innerText= "√"; } } function fun(){ var sex=document.getElementsByName('sex'); if(!sex[0].checked && !sex[1].checked){ sp[1].innerText="必選一項"; }else{ sp[1].innerText= "√"; } } inp[5].onblur = function (){ if(!emile.test(inp[5].value)){ sp[4].innerText = "必須包含@符號或者cn或者.net結尾"; }else{ sp[4].innerText= "√"; } } inp[6].onblur = function (){ if(!tel.test(inp[6].value)){ sp[6].innerText = "必須是11位元字開頭,以15,18,13開頭"; }else{ sp[6].innerText= "√"; } } inp[7].onblur = function (){ if(!t.test(inp[7].value)){ sp[7].innerText = "必須是010-68801717這種格式,前面三位是區號,後面是8位電話號,中間是-"; }else{ sp[7].innerText= "√"; } } inp[8].onblur = function (){ if(!shen.test(inp[8].value)){ sp[8].innerText = "必須是15到18位元字組成,18位的最後一位可以是X"; }else{ sp[8].innerText= "√"; } } inp[9].onblur = function (){ if(!qq.test(inp[9].value)){ sp[9].innerText = "必須是8到11位元字組成"; }else{ sp[9].innerText= "√"; } } inp[10].onblur = function (){ if(!te.test(inp[10].value)){ sp[10].innerText = "必須是8到11位元字組成"; }else{ sp[10].innerText= "√"; } } function fun1(){ var o=document.getElementById('o'); if(!city.test(o.value)){ sp[5].innerText = "必選一項"; return false; }else{ sp[5].innerText= "√"; return true; } } </script></body></html>