表1  字段1  字段2 GET来一个值 name  先搜索 字段1 如果没值,在搜索字段2。。这个有人有经验吗?

解决方案 »

  1.   

    表1  字段1  字段2 GET来一个值 name  先搜索 字段1 如果没值,在搜索字段2。。这个有人有经验吗?  如果字段1 搜索到N个结果,就循环N个结果,如果1个结果都没在搜索字段2,在循环字段2的值。
      

  2.   


    $n=$_GET['name']$sou="select * from xclass where Name like '%$n%'";
    $ss=$mysqli->query($sou);
    while($s=$ss->fetch_assoc()){
        echo $z=$s['Name'];
    }
    //判断上边的z有没值,没值就搜索 字段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'];
    }
    }
      

  3.   

    $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'];
    }
      

  4.   

    $sou[]  变量后边加了个 [] 符号代表什么意思?
      

  5.   

    空数组,然后 select 的结果赋值给他?
      

  6.   

    不是select的结果,是将那个sql串赋值给他。
    $arr[]='xx' ;  // 是在数组的后面加上一个值为xx的元素  索引从0,1,2,... 递增。