Dispaly crosstab

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
namtab
Forum Newbie
Posts: 3
Joined: Thu Nov 10, 2005 6:33 am

Dispaly crosstab

Post 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.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

post your code so we can see where your going wrong mate.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Exact error codes, too.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
Post Reply