PHP Connection Database Additions and deletions----multi-criteria Query

Source: Internet
Author: User

About the query, you can write directly on the main page to query

First, start by creating a form

<form method="Post"Action="crud.php"> <table> <tr><!--<td>--><!--number <input type="Text"Name="Id">--><!--</td>--> <td> &nbsp;&nbsp; name <input type="Text"Name="Name"> </td> <td> &nbsp;&nbsp; Sex <Select Name="Sex">
<OptionValue="> Please select </.Option> <option value="1"> Male </option> <option value="0"> Women </option> </select> </td> <td> &nbsp;&nbsp; Birth date <input type="Text"Name="birth_start ">--<input type= "text" Name=" birth_end "> </td> <td> &nbsp;&nbsp; class <input Type= "text "Name=" class "> </td> <td> <input type=" submit "Value=" check "> </td> </tr> </table></ Form>

2. Enquiry

if (!Empty ($_post)) {//$id = $_post[' id ']; $name = $_post[‘Name‘]; $sex = $_post[‘Sex‘]; $birth _start= $_post[‘Birth_start‘]; $birth _end = $_post[‘Birth_end‘]; $class = $_post[‘Class‘];
1//if (!empty ($name)) {//$sql. = "and name like '%{$name}% '";//}

2//$sql. =!empty ($id)? "and Sno like '%{$id}% '": "";$sql. =!empty ($name)?"and Sname like '%{$name}% '" :""; $sql. = ($sex! = "and Ssex = ' {$sex} ' ": Span style= "COLOR: #800000" "" "; if (!empty ($birth _start) &&! Empty ($birth _end)) {$sql. = "and sbirthday > ' {$birth _ Start} ' and Sbirthday < ' {$birth _end} ' ": " "; $data = $db->query ($sql)->fetch_all ();?

There are two ways to do this.

Above the ID column hidden, can write not write

Test it:

1. Open the homepage

2, check all 95033 classes

3. Click to find a check

4, success, if not rest assured can write a few conditions, as follows

Check it out.

5. Success-^

PHP Connection Database Additions and deletions----multi-criteria Query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.