我在install.packages("rJava"); library(rJava)
列(1,47,6)中有价值。如何获得所有价值?
我使用了以下代码。
user_id
此$array_data = array($project_id);
$query = "SELECT * FROM p
INNER JOIN pl ON p.pl_id = pl.pl_id
INNER JOIN user ON p.user_id = user.user_id WHERE
p.p_id=?";
$stmt = $conn->prepare($query);
$stmt->execute($array_data);
$result_data = $stmt->fetchAll( PDO::FETCH_ASSOC );
$ids = array();
foreach($result_data as $rows) {
$ids[] = $rows['user_id'];
}
$id = implode(',',$ids);
echo $id;
仅返回第一个值(1)。我需要所有3个值。请帮助&提前谢谢。
答案 0 :(得分:-1)
在循环之前声明$ids
数组并回显数组
$array_data = array($project_id);
$query = "select `user_id` from p
inner join pl on p.pl_id = pl.pl_id
inner join user on p.user_id = user.user_id where
p.p_id=?";
$stmt = $conn->prepare($query);
$stmt->execute($array_data);
$result_data = $stmt->fetchAll( PDO::FETCH_ASSOC );
$ids = array(); /* declare variable before loop */
foreach($result_data as $rows) {
$ids[] = $rows['user_id'];
}
$id = implode(',',$ids); /* output after loop */