我有一个看起来像这样的表:
| ID | INVOICE | SENDER |
---------------------------------------
| 01 | 001 | JAMMIE |
| 02 | 020 | HARLEY |
| 03 | 033 | HARLEY |
| 04 | 044 | JAMMIE |
| 05 | 055 | HARLEY |
| 06 | 066 | JAMMIE |
| 07 | 077 | HARLEY |
| 08 | 088 | HARLEY |
| .. | ... | ...... |
我希望运行查询以获取结果并将其存储在如下所示的数组中:
Array
(
[a] => JAMMIE
(
[0] => 001
[1] => 044
[2] => 066
)
[b] => HARLEY
(
[0] => 020
[1] => 033
[2] => 055
[3] => 077
[4] => 088
)
[c] ....
)
我的代码:
$sql=select invoice, sender from table group by sender;
$result=mysql_query($sql) or die(mysql_error());
while($myrow=MySQL_fetch_array($result,MYSQL_ASSOC))
{
extract($myrow);
echo "<pre>";
print_r($myrow);
echo "</pre>";
}
但是,阵列的print_r
并没有给我我所期望的阵列结构。变成这样:
Array
(
[invoice] => 001
[sender] => JAMMIE
)
Array
(
[invoice] => 002
[sender] => HARLEY
)
....
我应如何修改代码以获得所需的结果?