我使这里的内容更易于理解,因此: 我想在此处选择在Mysql表的“专业”字段中具有“例如”编码器的用户。因为正如您在此代码中所看到的,它将选择一个随机用户,但已登录的用户除外。而且我需要在AND之后再做一个条件(请参见代码行2),因此它会查找并仅推出带有“编码器”的用户写在行业领域。您还需要什么信息来帮助解决问题?
ps。它应该从列中选择-专业
public function whoToFollow1($user_id, $profileID){
$stmt = $this->pdo->prepare("SELECT * FROM `users` WHERE `user_id` != :user_id AND (what stetement need to be here) ORDER BY rand() LIMIT 1");
$stmt->execute(array("user_id" => $user_id));
$users = $stmt->fetchAll(PDO::FETCH_OBJ);
echo '<div class="wrap"><div class="inner"><div class="title"></div>';
foreach ($users as $user) {
答案 0 :(得分:0)
您只需要将您描述的条件添加到查询中,即
$profession = "coder";
$stmt = $this->pdo->prepare("SELECT * FROM `users` WHERE `user_id` != :user_id AND profession = :profession ORDER BY rand() LIMIT 1");
$stmt->execute(array("user_id" => $user_id, "profession" => $profession));
答案 1 :(得分:0)
$stmt = $this->pdo->prepare("SELECT * FROM `users` WHERE `user_id` != :user_id AND `profession`=:job ORDER BY rand() LIMIT 1");
$stmt->execute(array("user_id" => $user_id, "job" => $job));
Note: $job
will be used to represent the current job you wish to target.
答案 2 :(得分:0)
// I am assuming you have profession table with id and profession name/type
SELECT *
FROM `users`
INNER JOIN profession on users.profession_id = profession.id
WHERE `user_id` = :user_id
AND profession.id = :profession_id