[英]How to fetch 1 table users details using 2 table in php pdo?
Hi can anyone help am trying fetch all user data from database using php and pdo method 嗨,任何人都可以帮助尝试使用php和pdo方法从数据库中获取所有用户数据
i have two tables 1 table for users data, 2 for connected users id's , 我有两个表1个用于用户数据的表,2个用于连接的用户ID的表,
i want fetch only connected users profiles when users id exit in 2 table. 当用户ID在2表中退出时,我只想获取已连接的用户个人资料。
first i checked 2 table whether user id there or not. 首先,我检查2表是否有用户ID。 example a user connected to 2 other users , i got users ids and implode into array. 例如一个用户连接到其他2个用户,我得到了用户ID并内爆到数组中。 then i used to check 1 table Where In (:usid)
but its fetching only one user details 然后我曾经检查过1个表Where In (:usid)
但它仅获取一个用户详细信息
how can i fetch all details using 2 database 我如何使用2数据库获取所有详细信息
public function usrconnectedall(){
$bngusername2 = $_SESSION['bngusername'];
$this->query("SELECT * FROM bng_users WHERE bng_username=:bngusername2");
$this->bind(":bngusername2", $bngusername2);
$row = $this->getSingleRow();
//First Method (Requested) user profile id
$bngrequesteduserid = $row['id'];
$this->query("SELECT * FROM bng_connect WHERE bng_requesteduser_id=:bngrequesteduserid");
$this->bind(":bngrequesteduserid", $bngrequesteduserid);
$row2 = $this->resultSet();
foreach ($row2 as $k) {
$test[] = $k['bng_connecteduser_id'];
}
$usid = implode(',', $test);
$this->query("SELECT * FROM bng_users WHERE id IN (:usid)");
$this->bind(":usid", $usid);
$row3 = $this->resultSet();
foreach ($row3 as $a){
echo $a['bng_username'];
}
}
This is answer i found. 这是我找到的答案。 now am able to fetch users data 现在能够获取用户数据
$usid = implode(',', $test);
$this->query("SELECT * FROM bng_users WHERE FIND_IN_SET (id, :usid)");
$this->bind(':usid', $usid);
$row3 = $this->resultSet();
return $row3;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.