View Single Post
Old 04-12-2008, 12:27 AM   #1 (permalink)
benton
The Contributor
 
Join Date: Apr 2008
Posts: 78
Thanks: 0
benton is on a distinguished road
Default Creating a table from loaded data

In this scenario, there are three fields in a database, group, name and data, that consists of comma spearated lists. I am trying to read those in, sort them and make a three column table from the data. So I have something like this after reading in the data:
PHP Code:
$group explode(","mysql_group_column);
$name explode(","mysql_name_column);
$data explode(","mysql_data_column);

for (
$i 0$i count($group); ++$i)
{
  
$extraArray[] = array('group' => $group[$i], 'name' => $name[$i], 'data' => $data[$i]);

After the above, I have an array like
HTML Code:
Array
(
    [0] => Array
        (
            [group] => Metal Information
            [name] => Cut
            [data] => Clear
        )
    [1] => Array
        (
            [group] => Metal Information
            [name] => type
            [data] => Strong
        )
    [2] => Array
        (
            [group] => Stone Information
            [name] => Length
            [data] => 4\"
        )
    [3] => Array
        (
            [group] => Stone Information
            [name] => Color
            [data] => White
        )
    [4] => Array
        (
            [group] => Stone Information
            [name] => Width
            [data] => 3\"
        )
    [5] => Array
        (
            [group] => Stone Information
            [name] => Type
            [data] => Diamond
        )
)
I want to be able to output a table that looks something like
HTML Code:
 Stone Information
  Length 4"
  Color  white
  Type   Diamond
  
 Metal Information
  Cut    Clear
  Type   Strong
I think my problem is that the initial data shouldn't all be read into one array. But since the group item can be anything and any number of groups, I can't see how to programatically read this in and separate it right from the start. Can someone please provide some ideas on how I can accomplish this?
benton is offline  
Reply With Quote