Novice advice: how to write php multi-condition query search MYsql
苏小刚
苏小刚 2018-08-13 16:23:57
0
7
1391

According to such query conditions, how to search for the user name and password in the database?

2.png1.png

苏小刚
苏小刚

reply all(6)
中国推广网

Directly add multiple and   conditions after where. If the value is not selected, it will be empty.

Summer

Cannot upload pictures. . .

Summer

good

Summer

Add the last one yourself

Summer

Add the last one yourself

ll

if($chengbenjia!=0){

switch ($chengbenjia) {

case 1:

$sql = $sql."and cost_price>=0 and cost_price<=99 ";

break;

case 2:

$sql = $sql."and cost_price>=100 and cost_price<200 ";

break;

case 3:

$sql = $sql."and cost_price>=200 and cost_price<=299 ";

break;

case 4:

$sql = $sql."and cost_price>=300 ";

break;

case 5:

$sql = $sql."and cost_price =0 ";

break;

}

}

if($shoujia!=0){

switch ($shoujia) {

case 1:

$sql = $sql."and sellprice>=0 and sellprice<=99 ";

break;

case 2:

$sql = $sql."and sellprice>=100 and sellprice<200 ";

break;

case 3:

$sql = $sql."and sellprice>=200 and sellprice<=299 ";

break;

case 4:

$sql = $sql."and sellprice>=300 ";

break;

}

}


我也是刚学php没多久 我用的 字符串拼接做的 有没有别的更好地办法我不太清楚

  • reply Do I need to splice sql statements based on conditions and passed values? How to write sql statements? I am also a novice and I just learned it for a week.
    苏小刚 author 2018-08-13 19:18:06
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template