我有一个函数可以从我的数据库中选择男性、女性或两种性别。
函数看起来像:
function getMembers($sex = null) {
if (is_null($sex)) {
$sex = (0 || 1);
}
$query = $conn->prepare("SELECT username FROM users WHERE sex = :sex");
$query->execute(array(
':sex' => $sex
));
$members_results = $query->fetchAll(PDO::FETCH_ASSOC);
}
我这样称呼查询:
获取成员(0);(取来女孩很好)
获取成员(1);(把伙计们抓得很好)
获取成员();(只取男生)
我相信 $sex = (0 || 1); 线是错误的。
你会如何解决它?谢谢
Ps.:我的查询实际上看起来像:
$query = $conn->prepare("SELECT picture_path, profile_picture, username, last_visit, signup_date, settings, sex FROM tusers
WHERE profile_picture IS NOT NULL
AND settings LIKE '1,%'
AND sex = :sex
AND last_visit BETWEEN CURDATE() - INTERVAL 9 DAY AND CURDATE()
AND signup_date < CURDATE() - INTERVAL 10 DAY
ORDER BY RAND()
LIMIT 15");