Page 1 of 1

Dispaly crosstab

Posted: Thu Nov 10, 2005 6:43 am
by namtab
Hi,

Im totally new to php and need some help please.

I have a mssql table with the following data

Name Amount Month
------- ---------- --------

John 500.00 10/2005
Jack 600.00 11/2005


The result Im trying to get using php is :-

Name 10/2005 11/2005
------- ---------- -----------
John 500.00
Jack 600.00


I am total stupped I can get the column headings but I can't seem to get the amounts in the correct columns. Could some please point me in the write direct as my code now looks a complete mess with for,while etc.......

any help would be much appreciated

Thx.

Posted: Thu Nov 10, 2005 6:49 am
by jayshields
post your code so we can see where your going wrong mate.

Posted: Thu Nov 10, 2005 8:25 am
by m3mn0n
Exact error codes, too.

Posted: Thu Nov 10, 2005 8:38 am
by Jenk

Code: Select all

<?php

$result = mysql_query('SELECT * FROM table');
$data = array();
$i = 0;
while ($row = mysql_fetch_assoc($result)) {
    $data[$i]['name']  = $row['name'];
    $data[$i][$row['month']] = $row['amount'];
    $i++;
}

print_r($data);

?>
Give that a try :)