我正在尝试获取用户的所有朋友请求并显示它们。但是,print_r只会在屏幕上打印“数组”。当我使用print / echo和数组索引(例如$ arrayname [0])时,它可以工作。但是,它仅适用于索引的第一个(0)值。其余没有显示(例如,$ arrayname [0]返回一个值,但$ arrayname [1]不会),即使数据库中有多个值。这是我的代码
$fr_requests = $db->prepare("SELECT uid, requester, date_requested FROM friends WHERE rid= :uid AND accepted= 'c'");
$fr_requests-> bindParam(':uid', $user_number, PDO::PARAM_INT);
$fr_requests->execute();
$request_count = $fr_requests->rowCount();
if($request_count == 0) {
$_SESSION['no_fr_requests'] = "1";
} else {
$req_person_id = $fr_requests->fetchAll(PDO::FETCH_COLUMN, 0);
$req_person_name = $fr_requests->fetchAll(PDO::FETCH_COLUMN, 1);
$date_requested = $fr_requests->fetchAll(PDO::FETCH_COLUMN, 2);
$_SESSION['fr_requests_count'] = $request_count;
$_SESSION['req_person_id'] = $req_person_id;
$_SESSION['req_person_name'] = $req_person_name;
$_SESSION['date_requested'] = $date_requested;
print ($request_count.'<br>');
print_r ($req_person_id.'<br>');
print_r ($req_person_name.'<br>');
print_r ($date_requested.'<br>');
}
感谢所有帮助,谢谢。