2012-09-26 75 views
4

我試圖從一張表中拉出多行。我試圖拉取所有男性或所有女性在不同的郵政編碼。使用php mysql在單個表中進行多項選擇

<?php 
$zipCodes = array("55555", "66666", "77777", etc...); 

$fetchUser = mysql_query("select * from users where gender = '$_POST[gender]' ".implode(" or zipCode = ", $zipCodes)." order by id desc"); 
while($var = mysql_fetch_array($fetchUser)) { 
    code... 
} 
?> 
+0

我想你忘了問一個問題。你的代碼有什麼問題? –

+0

歡迎來到stackoverflow ..請解釋你遇到的問題..你的帖子中沒有問題。 – BugFinder

回答

0
// Prevent SQL injection for user input 
$fetchUser = mysql_query("select * from users where gender = '".filter_var($_POST[gender], FILTER_SANITIZE_STRING)."' OR zipCode IN (".implode(",", $zipCodes).") order by id desc");)