Aaron
Aaron

Reputation: 11673

How would I construct a mysql query to use multiple AND operators?

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

Upvotes: 0

Views: 575

Answers (3)

Bastardo
Bastardo

Reputation: 4152

you'll do it like this

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

Upvotes: 0

Shakti Singh
Shakti Singh

Reputation: 86406

Assuming you are talking to construct query based on PHP input variables

$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 );

Upvotes: 2

crimson_penguin
crimson_penguin

Reputation: 2778

You do it exactly like you just said.

Upvotes: 8

Related Questions