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.