我有一个MySQL表,包含以下列:
id : title : message : date
1 : blah : blah : 27/12/2012
我查询了它并将其存储在一个数组中。如何获得特定ID下的各个列。例如,我想获得行ID = 1,并获得标题,消息等。然后是第二行和第三行。如何从数组中获取信息。像
$array[1]["date"]; ( I tried it and it never worked)
基本上需要以关联数组的形式获取结果,并循环遍历所有结果。您的所有结果将以
的形式显示。阵列(
);
'id' => 1;'title' => 'blah',
'message' => 'blah',
'date' => '27/12/2012'
示例:
$array = array();
while ($row = fetch_assoc($result)) { // use your favorite fetch method here
$array[$row['id']] = $row;
}
echo $array[1]["date"]; // now will work (if you have such id)