在以下示例中,我需要将联系人作为数组。
正确的做法是什么。
$query = "SELECT cl.name, ct.phone, ct.address
FROM clients cl
LEFT JOIN contacts ct ON cl.id = ct.id";
$statement = $conexion->query($query);
while($row = $statement->fetch_assoc()) {
$data[] = array(
'name'= $row['name'],
'contacts' = array(
'phone'= $row['phone'],
'address'= $row['address']
)
)
};
echo json_encode($data);
答案 0 :(得分:0)
while($row = $statement->fetch_assoc())
{
$data[] = array(
'name'=> $row['name'],
'contacts' => array(
'phone'=> $row['phone'],
'address'=> $row['address']
)
);
}