如何构建一个mysql查询以使用多个AND运算符?

时间:2011-04-16 15:30:36

标签: php mysql

例如"SELECT * FROM date WHERE name = 'etc' AND lastname = 'etc' AND etc='etc'";

3 个答案:

答案 0 :(得分:8)

你完全按照刚刚说的那样去做。

答案 1 :(得分:3)

假设您正在讨论基于PHP输入变量构造查询

$fields = array( "name", "lastname", "etc" ) ;
foreach( $fields as $field)
{
   $clause[]=$field."='".mysql_real_escape_string($_POST[$field])."'";
}
$query = "SELECT * from `date` where "
         .implode( " AND ", $clause );

答案 2 :(得分:0)

你会这样做

eg "SELECT * FROM date WHERE name = 'etc' AND lastname = 'etc' AND etc='etc'";