Home Backend Development PHP Tutorial PHP paging and regular verification code implementation

PHP paging and regular verification code implementation

Jul 28, 2018 am 11:33 AM

This article introduces you to the code implementation of PHP paging and regular verification. It has a good reference value and I hope it can help friends in need.

Paging:

<?php
header("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[&#39;page&#39;]){
       $page=1;
}else{

     if($page<1){
      $page=1;
     }elseif($page>$max){
      $page=$max;

     }else{

      $page=$_GET[&#39;page&#39;];
     }

}
$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[&#39;id&#39;]?></td>
         <td><?php echo $v[&#39;name&#39;]?></td>
         <td><?php echo $v[&#39;fen&#39;]?></td>
         <td><?php echo $v[&#39;dj&#39;]?></td>
         <td><?php echo $v[&#39;zhuang&#39;]?></td>
         <td><?php echo $v[&#39;kucun&#39;]?></td>
         <td><?php echo $v[&#39;chan&#39;]?></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>
Copy after login

Regular verification:

<!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(&#39;input&#39;);
           var sp = document.getElementsByTagName(&#39;span&#39;);
           var o = document.getElementsByTagName(&#39;option&#39;);
           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(&#39;sex&#39;);
           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(&#39;o&#39;);  
               if(!city.test(o.value)){

                sp[5].innerText = "必选一项";
                return false;

              }else{

                sp[5].innerText= "√";
                return true;

             }
       }
   </script>

</body>
</html>
Copy after login

Related recommendations:

PHP regular verification email method, PHP verification Email method

PHP paging class code, php paging code

The above is the detailed content of PHP paging and regular verification code implementation. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles