Search for the values of N fields in the same table.

Source: Internet
Author: User
Search for the values of N fields in the same table. Table 1 Field 1 field 2

GET to a value name

First, search for field 1. if there is no value, search for field 2 .. Is there anyone with experience?


Reply to discussion (solution)



Table 1 Field 1 field 2

GET to a value name

First, search for field 1. if there is no value, search for field 2 .. Is there anyone with experience?

If field 1 finds N results, it loops N results. if one result is not in field 2, it is in the value of loop field 2.

If there are M fields, you will search for M times ?!
Then you can search in the loop.
No one will do this anyway.

You can judge it one by one, but it is troublesome.

If there are M fields, you will search for M times ?!
Then you can search in the loop.
No one will do this anyway.

Only two fields are searched. if two fields are not found, the system exits.

You can judge it one by one, but it is troublesome.


Do you have any ideas? Swite?

If... else

If... else

$ N = $ _ GET ['name']

$ Sou = "select * from xclass where Name like '% $ n % '";
$ Ss = $ mysqli-> query ($ sou );
While ($ s = $ ss-> fetch_assoc ()){
Echo $ z = $ s ['name'];
}
// Judge whether the above z has no value. if there is no value, search for field 2.
If (isset ($ z )){
$ Zais = "select * from xclass where Item1 like '% $ n % '";
$ Zaiss = $ mysqli-> query ($ zais );
While ($ sss = $ zaiss-> fetch_assoc ()){
Echo $ zaisou = $ sss ['item1'];
}
}


$n = $_GET['name'];$sou[] = "select * from xclass where Name like '%$n%'";$sou[] = "select * from xclass where Item1 like '%$n%'";foreach($sou as $sql) {  $rs = $mysqli->query($sql);  if($rs->num_rows) break;}while($sss = $rs->fetch_assoc()){    echo $zaisou=$sss['Item1'];}

$ Sou [] what does it mean to add a [] symbol behind the variable?

Code: it is an array

Correction:
Represents an array.

Empty array, and assign the select result to him?

It is not the result of select. it is to assign the SQL string to him.
$ Arr [] = 'XX'; // adds an element index with a value of xx after the array from 0, 1, 2.

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.