<?php $sql = "select * from student where 1"; if($name) { $sql .= " and name = '$name'"} if($sex) { $sql .= " and sex = '$sex'"} if($deep) { $sql .= " and deep = '$deep'"} ?>