我有四个<input type="text" name=""/>这样的输入值
action到处理的php页面
有没有什么方法能够合理的让php页面的sql语句判断当那个字段为空时,就不以那个为搜索的条件了
除了穷举,还有什么方法?
$sql="select * from table where ..."
实例:
html
<form action="chuli.php" method="post">
姓名:<input type="text" name="name">
年龄: <input type="text" name="age">
性别: <input type="text" name="sex">
身高: <input type="text" name="height">
</form>chuli.php
//连接数据库部分省略
$sql="select * from student where name='$name' and age='$age' and sex='$sex' and height='$height';// 这个是所有的
$result = mysql_query($sql,$con);//除了穷举以外,有没有什么方法,判断那几个Input数据为空的时候的$sql进行判断的方法?
//如果是4个input的情况下的时候是 4+6+4+1+1=16种情况,应该对吧? c41+c42+c43+c44+1=4+6+4+1+1=16?
action到处理的php页面
有没有什么方法能够合理的让php页面的sql语句判断当那个字段为空时,就不以那个为搜索的条件了
除了穷举,还有什么方法?
$sql="select * from table where ..."
实例:
html
<form action="chuli.php" method="post">
姓名:<input type="text" name="name">
年龄: <input type="text" name="age">
性别: <input type="text" name="sex">
身高: <input type="text" name="height">
</form>chuli.php
//连接数据库部分省略
$sql="select * from student where name='$name' and age='$age' and sex='$sex' and height='$height';// 这个是所有的
$result = mysql_query($sql,$con);//除了穷举以外,有没有什么方法,判断那几个Input数据为空的时候的$sql进行判断的方法?
//如果是4个input的情况下的时候是 4+6+4+1+1=16种情况,应该对吧? c41+c42+c43+c44+1=4+6+4+1+1=16?
解决方案 »
- 不能判断脚本,而执行了PHP语句
- 超级经典SQL语句大全分享(绝对值得收藏)
- php做网站,统计总的访问次数。
- 生成验证码的问题?
- 这句话怎么解释?? This will result in significant performance gains
- 在linux环境下,php语法出错,怎样让php编译后提示编译错误,错误在哪?
- php如何读取证书来进行控制 ???
- SMARTY我只需要简单的模板功能,在发发表的时候要带哪几个文件??
- 问一个问题
- 传值的时候出现错误
- 后台的list页面,在顺序里点向上就上移一位,点下降就下降一位,然后前台也同时变化,这个怎么实现的?
- #新手提问#有关天气预报的小偷程序
$r[] = "$k='$v'";$sql = "select * from student where ". join(' and ', $r);
if($_POST['name'] != ''){
$where .= " and name= ‘".$_POST['name']."'";
}
if($_POST['age'] != ''){
$where .= " and age= ‘".$_POST['age']."'";
}
if($_POST['sex'] != ''){
$where .= " and sex= ‘".$_POST['sex']."'";
}
if($_POST['height'] != ''){
$where .= " and height= ‘".$_POST['height']."'";
}
$sql="select * from student where". $where
$sql="select * from student where 1=1";
if(!empty($_POST['name'])) $sql=" and name=$_POST[name]'";
if(!empty($_POST['age'])) $sql=" and age=$_POST[age]'";
if(!empty($_POST['sex'])) $sql=" and sex=$_POST[sex]'";
if(!empty($_POST['height'])) $sql=" and height=$_POST[height]'";
if(!empty($_POST['name'])) $sql=" and name='$_POST[name]'";
if(!empty($_POST['age'])) $sql=" and age='$_POST[age]'";
if(!empty($_POST['sex'])) $sql=" and sex='$_POST[sex]'";
if(!empty($_POST['height'])) $sql=" and height='$_POST[height]'";