Q:

Make a sideways data table. (Headers on the left, data on right, two columns) php logic error

This is most definitely a logic error, but I just cannot seem to figure out in what way I am supposed to do this. I need to put the headers of the table on left-hand side, and the data for each on the right column. 
$value = pg_num_fields($result);
$line = pg_fetch_array($result, NULL, PGSQL_ASSOC); 
//as it's pulling from just one line in the database as specified early on in code, but that works
foreach($line as $colvalue) {
    for ( $i=0; $i<$value; $i++ ) {
        $header = pg_field_name($result, $i);
        echo "<tr><th>$header</th>";
        echo "<td>$colvalue</td></tr>"; 

    }
}

This goes through the headers correctly, but repeats the x amount of them y times. The data fields to the right of the headers get repeated x times. I tried putting just "$line" where $colvalue currently is and removing the foreach line, but that just returns "Array" (but with the headers not repeating) where the data should be. 
the above code prints off like...
a x
b x
c x
a y
b y
c y
a z 
b z
c z
where I put $line in it replaces the x y and z with just Array. I tried doing $line[$i] as well, but that just made the second column empty. Any help would be appreciated. 

A:

separate for loop under $line = blah and remove the foreach loop in the question statement
for ( $h = 0, $i = 0; $h<$value; $h++ ) { //going through the amount of values
    foreach($line as $col ) { 
        $array[$i++] = $col; //put one element in the array and bump it
    }
}

and just switch $colvalue in the echo below to whatever your array is like
echo $array[i];

