0

I have a table that looks like this:

|    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   |
|    ..    |     ...     |   ......   |

I expect to run a query to get results and store in array that looks like this:

Array
(
    [a] => JAMMIE
        (
            [0] => 001
            [1] => 044
            [2] => 066
        )
    [b] => HARLEY
        (
            [0] => 020
            [1] => 033
            [2] => 055
            [3] => 077
            [4] => 088
        )
    [c] ....
)

My codes:

$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>";
}

However, print_r of the array didn't gave me my expected array structure. It became like this:

Array
(
     [invoice] => 001
     [sender] => JAMMIE
)
Array
(
     [invoice] => 002
     [sender] => HARLEY
)
....

Any ways should I modify my codes to get the results I need ?

hatched
  • 795
  • 2
  • 9
  • 34

0 Answers0