


PHP data access query keywords, PHP data keywords_PHP tutorial
Query keywords for php data access, php data keywords
The example in this article shares the implementation code of php query operation for your reference. The specific content is as follows
1. One keyword query
Main page:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>汽车查询页面</title> </head> <body> <h1>汽车查询页面</h1> <?php include("QiChe.class.php"); $db=new QiChe(); //保留输入查询的内容 $cx=""; $value=""; if(!empty($_POST["name"]))//判断查询内容是否为空 { $name=$_POST["name"]; $cx=" where name like '%{$name}%'";//查询的字符串 $value=$name; } ?> <br> <form action="QiChe.php" method="post"> <div> 请输入查询内容:<input type="text" name="name" value="<?php echo $value; ?>"/> <input type="submit" value="查询"/> </div> </form> <br /> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>代号</td> <td>汽车名称</td> <td>油耗</td> <td>功率</td> <td>价格</td> </tr> <?php $sql="select * from Car".$cx; $attr=$db->query($sql); foreach ($attr as $v) { //使输入查询的关键字变色,处理name //$rp="<mark>{$value}</mark>"; $rp="<span style='color:red'>{$value}</span>"; $arr=str_replace($value,$rp,$v[1]); echo "<tr> <td>{$v[0]}</td> <td>{$arr}</td> <td>{$v[4]}</td> <td>{$v[5]}</td> <td>{$v[7]}</td> </tr>"; } ?> </table> </body> </html>
Packaging class:
<?php class QiChe { public $localhost="localhost";//服务器 public $uid="root";//用户名 public $password="";//密码 //执行查询语句sql方法: //参数的含义:$sql代表要执行的sql语句;$type代表sql语句的类型,自义0为查询,1为其他(增删改查);$db代表要查询的数据库 public function Query($sql,$type="0",$db="mydb") { $dbconnect=new MySQLi($this->localhost,$this->uid,$this->password,$db); !mysqli_connect_error() or die("连接失败 !"); $result=$dbconnect->query($sql); if($type==0) { return $result->fetch_all(); } else { return $result; } } }
Run result:
2. Multiple keyword query
Main page:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>汽车查询页面</title> </head> <body> <h1>汽车查询页面</h1> <br> <?php include ("./DBDA.class.php"); $db=new DBDA(); $cx=""; $value=""; $value1=""; $tj1=" 1=1";//条件1的判断name $tj2=" 1=1";//条件2的判断brand if(!empty($_POST["name"])) { $name=$_POST["name"]; $tj1="name like '%{$_POST['name']}%'"; $value=$name; } if(!empty($_POST["brand"])) { $name1=$_POST["brand"]; $tj2="brand= '{$_POST['brand']}'"; $value1=$name1; } $cx=" where $tj1 and $tj2";//查询字符串 ?> <form action="ChaXun1.php" method="post"> <div> 请输入名称:<input type="text" name="name" value="<?php echo $value; ?>"/> 系列:<input type="text" name="brand" value="<?php echo $value1; ?>"> <input type="submit" name="" value="查询"> </div> </form> <br> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>代号</td> <td>汽车名称</td> <td>系列</td> <td>价格</td> <td>油耗</td> <td>功率</td> </tr> <?php $sql="select * from Car".$cx; $attr=$db->Query($sql); foreach ($attr as $v) { //处理name //$rp="<mark>{$value}</mark>"; $rp="<span style='color:red'>{$value}</span>"; $str=str_replace($value,$rp,$v[1]); echo "<tr> <td>{$v[0]}</td> <td>{$str}</td> <td>{$v[2]}</td> <td>{$v[7]}</td> <td>{$v[4]}</td> <td>{$v[5]}</td> </tr>"; } ?> </table> </body> </html>
Run result:
The above is the entire content of this article. I hope it will be helpful to everyone in learning PHP programming.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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,

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

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.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.
