-1
想要打印來自兩個不同表格的參與者信息,如firstName,organization。查詢工作正常,因爲它提供了期望的結果。但是當我嘗試打印提取的數據時,它會返回一個錯誤。顯示來自PDO中多個表的記錄mysql
function get_all_participant(){
include 'connection.php';
$sql = '
select p1.fname
, p1.organization
, p1.state
, p2.created
from participant p1
INNER JOIN programme_participant p2
ON p1.id = p2.participant_id
';
try{
$results = $db->prepare($sql);
$results->execute();
} catch (Exception $e){
echo "Error! " . $e->getMessage() . "<br/>";
return false;
}
return $results->fetch();
}
<?php foreach (get_all_participant() as $item){
echo $item['fname'];
}?>
輸出(錯誤):
警告:非法串偏移 'FNAME'
get_all_participant()返回什麼? – Akintunde007
你不明白。數組'get_all_participant()'的結果是什麼? – Akintunde007
它返回參與者信息。 'return $ results-> fetch();' – GKumar