Home  >  Article  >  Backend Development  >  How to implement conditional query in php

How to implement conditional query in php

藏色散人
藏色散人Original
2020-10-15 11:12:465360browse

How to implement conditional query in php: first call the previously encapsulated class; then use keyword fuzzy query; then create a form, submit the data to the current page, extract the keyword query; and finally use PHP code Traverse the elements in the table and turn the keywords into red.

How to implement conditional query in php

Recommended: "PHP Video Tutorial"

1. Single condition Query is a query with only one condition:

1. First call the previously encapsulated class, and then use keywords to fuzzy query:

2. Create a form, submit the data to the current page, and extract the keyword query:

姓名:

3. Traverse the elements in the table and turn the keywords into red:

query($sql);
foreach($arr as $v)
{
    $str = str_replace($Sname,"{$Sname}",$v[1]);//用span标签使关键字变为红色,
    echo "
"; } ?>

Final result:

How to implement conditional query in php

## 2. Multi-condition query:

1. First make a form and create a table to display the table:

姓名 性别 班级
{$str} {$v[2]} {$v[4]}
代号 名称 系列 上市时间 价格

2. Call the encapsulation class, create corresponding conditions, and check whether the data is empty :

3. Use PHP code to traverse the database table and turn the keywords into red (php should be embedded in the table):

query($sql);foreach($arr as $v)
{
    $str = str_replace($name,"{$name}",$v[1]);
    echo "
    {$v[0]}
    {$str}
    {$v[2]}
    {$v[3]}
    {$v[7]}
";}?>

The final result is:

How to implement conditional query in php

The above is the detailed content of How to implement conditional query in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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