多条件查询语句示范

| |
[不指定 2006/04/10 09:39 | by Space.As ]
if($category || $make || $model || $condition) {
  // build query string
  $query = "SELECT * FROM $dbvin WHERE";
  if($category) { $query .= " category='$category' AND"; }
  if($make) { $query .= " make='$make' AND"; }
  if($model) { $query .= " model LIKE '%$model%' AND"; }
  if($condition) { $query .= " condition='$condition'"; }
  // trim extra AND if neccessary
  if(substr($query, strlen($query)-4, 4) == ' AND') {  $query = substr($query, 0, strlen($query)-4); }
} else {
  $query = "SELECT * FROM $dbvin";
}

.= 最基础的东西,我开始写的 多条件查询 写的好复杂, 看到这个写法后 才发觉 .= 这个运算符号的用处.
学习笔记 | 评论(0) | 引用(0) | 阅读(1762)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]