Searches for the values of n fields in the same table.

Source: Internet
Author: User
Table 1 Field 1 Field 2

Get to a value of name

Search Field 1 First if no value, in search field 2: Does anyone have any experience with this?


Reply to discussion (solution)



Table 1 Field 1 Field 2

Get to a value of name

Search Field 1 First if no value, in search field 2: Does anyone have any experience with this?

If field 1 searches for n results, it loops n results, if 1 results are not in the Search field 2, in the value of the Loop field 2.

If there are m fields, you search m times?!
Then you can search through the loop.
No one's going to do this anyway.

In order to judge the next, but it is troublesome point.

If there are m fields, you search m times?!
Then you can search through the loop.
No one's going to do this anyway.

only 2 fields are searched, and 2 fields exit without finding the result.

In order to judge the next, but it is troublesome point.


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 '];
}
Determine if z above has value, no value search 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 '];}

What do you mean by adding a [] symbol behind the $sou [] variable?

Code it's an array

Correct:
Represents it as an array

An empty array, and then the result of select is assigned to him?

Not the result of a select, it is to assign the SQL string to him.
$arr []= ' xx '; is the index of an element with a value of XX appended to the array from 0,1,2, ... Increasing.

  • 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.