php新手求助 实现多条件组合查询 100
$s1=$_POST['s1'];$s2=$_POST['s2'];$text=$_POST['text'];$string="SELECT*FROMdemowhere1...
$s1=$_POST['s1'];
$s2=$_POST['s2'];
$text=$_POST['text'];
$string="SELECT * FROM demo where 1=1";
if($s1!="")
{$string.="and file_keyword1='$s1'";}
elseif ($s2!="")
{$string.="and file_keyword2='$s2'";}
elseif ($text!="")
{$string.="and file_keyword3='$text'";}
//省略数据库连接
$result = mysql_query($string);
while($row = mysql_fetch_array($result))
{
echo $row['id'] . " " . $row['file_name'];
echo "<br />";
}
s1 s2 text 分别是表单控件传过来的值,我想实现多条件组合查询 展开
$s2=$_POST['s2'];
$text=$_POST['text'];
$string="SELECT * FROM demo where 1=1";
if($s1!="")
{$string.="and file_keyword1='$s1'";}
elseif ($s2!="")
{$string.="and file_keyword2='$s2'";}
elseif ($text!="")
{$string.="and file_keyword3='$text'";}
//省略数据库连接
$result = mysql_query($string);
while($row = mysql_fetch_array($result))
{
echo $row['id'] . " " . $row['file_name'];
echo "<br />";
}
s1 s2 text 分别是表单控件传过来的值,我想实现多条件组合查询 展开
1个回答
展开全部
$s1=$_POST['s1'];
$s2=$_POST['s2'];
$text=$_POST['text'];
$string="SELECT * FROM demo where 1=1";
if($s1!=""){
$string.="and file_keyword1='{$s1}'";
}elseif ($s2!=""){
$string.="and file_keyword2='{$s2}'";
}elseif ($text!=""){
$string.="and file_keyword3='{$text}'";
}
//省略数据库连接
$result = mysql_query($string);
while($row = mysql_fetch_array($result)){
echo $row['id'] . "," . $row['file_name'];
echo "<br />";
}
$s2=$_POST['s2'];
$text=$_POST['text'];
$string="SELECT * FROM demo where 1=1";
if($s1!=""){
$string.="and file_keyword1='{$s1}'";
}elseif ($s2!=""){
$string.="and file_keyword2='{$s2}'";
}elseif ($text!=""){
$string.="and file_keyword3='{$text}'";
}
//省略数据库连接
$result = mysql_query($string);
while($row = mysql_fetch_array($result)){
echo $row['id'] . "," . $row['file_name'];
echo "<br />";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询