如何在数据库中搜索数组在哪里
How to search in database where is array
我有这个mysql
查询:
$Nusers = mysql_query("SELECT user_id FROM dotp_user_task_type WHERE user_task_types_id = '$select1'");
$row = mysql_fetch_array($result);
它获取所有具有特定 ID 任务的用户 ID。所以,现在我需要获取他们的名字和姓氏,但我不知道如何在 $row 是带数字的数组时使用 WHERE。
$Nusers = mysql_query("SELECT CONCAT(contact_first_name, ' ', contact_last_name) FROM dotp_user_contacts WHERE user_id = '$row'");
请帮忙......
为什么不像
那样将两个查询结合起来
SELECT CONCAT(contact_first_name, ' ', contact_last_name) as fullname
FROM dotp_user_contacts
WHERE user_id IN ( SELECT distinct user_id FROM dotp_user_task_type
WHERE user_task_types_id = '$select1' );
(OR) 使用简单的 JOIN
like
SELECT CONCAT(duc.contact_first_name, ' ', duc.contact_last_name) as fullname
FROM dotp_user_contacts duc
JOIN dotp_user_task_type dtt ON duc.user_id = dtt.user_id
WHERE dtt.user_task_types_id = '$select1';
使用IN
-
" ....WHERE user_id IN (" .implode(",", $row). ")"
试试这个..
使用IN
在mysql
中搜索数组值
$datauserid=array();
$Nusers = mysql_query("SELECT user_id FROM dotp_user_task_type WHERE user_task_types_id = '$select1'");
while($row = mysql_fetch_array($Nusers))
{
$datauserid[]=$row['user_id'];
}
$userid=implode(",",$datauserid);
$Nusers = mysql_query("SELECT CONCAT(contact_first_name, ' ', contact_last_name) FROM dotp_user_contacts WHERE user_id IN ($userid)");
我有这个mysql
查询:
$Nusers = mysql_query("SELECT user_id FROM dotp_user_task_type WHERE user_task_types_id = '$select1'");
$row = mysql_fetch_array($result);
它获取所有具有特定 ID 任务的用户 ID。所以,现在我需要获取他们的名字和姓氏,但我不知道如何在 $row 是带数字的数组时使用 WHERE。
$Nusers = mysql_query("SELECT CONCAT(contact_first_name, ' ', contact_last_name) FROM dotp_user_contacts WHERE user_id = '$row'");
请帮忙......
为什么不像
那样将两个查询结合起来SELECT CONCAT(contact_first_name, ' ', contact_last_name) as fullname
FROM dotp_user_contacts
WHERE user_id IN ( SELECT distinct user_id FROM dotp_user_task_type
WHERE user_task_types_id = '$select1' );
(OR) 使用简单的 JOIN
like
SELECT CONCAT(duc.contact_first_name, ' ', duc.contact_last_name) as fullname
FROM dotp_user_contacts duc
JOIN dotp_user_task_type dtt ON duc.user_id = dtt.user_id
WHERE dtt.user_task_types_id = '$select1';
使用IN
-
" ....WHERE user_id IN (" .implode(",", $row). ")"
试试这个..
使用IN
在mysql
$datauserid=array();
$Nusers = mysql_query("SELECT user_id FROM dotp_user_task_type WHERE user_task_types_id = '$select1'");
while($row = mysql_fetch_array($Nusers))
{
$datauserid[]=$row['user_id'];
}
$userid=implode(",",$datauserid);
$Nusers = mysql_query("SELECT CONCAT(contact_first_name, ' ', contact_last_name) FROM dotp_user_contacts WHERE user_id IN ($userid)");