Forum Moderators: coopster

Message Too Old, No Replies

Generate a Table with Rows and Columns

         

HoboTraveler

2:24 pm on Sep 15, 2008 (gmt 0)

10+ Year Member



Hi All,

I need to generate this table or grid with values from the database.

The data needs to be sorted by the column and not row.

Example:

A E G
A E H
B E I
C F J
D G K

Does anyone know howto do this? Do I have to make multiple calls to the database for every new column?

TIA

jatar_k

2:42 pm on Sep 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are they bound across the columns or are the columns sorted individually?

you could pull them all into an array, or multiple arrays, and sort the array(s)

or sort them out of mysql, though if they aren't bound then you would probably have to pull them individually

HoboTraveler

3:08 pm on Sep 15, 2008 (gmt 0)

10+ Year Member



Yes, the data is bound across all columns, not individual columns.

So the A on the first column is always displayed on the first column.

Are you saying I can sort the one big array? I would I continue the array on the next column?

TIA

jatar_k

3:37 pm on Sep 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



array_multisort() [php.net]

HoboTraveler

2:25 pm on Sep 16, 2008 (gmt 0)

10+ Year Member



Hello,

Could someone post some pseudo code? I was able to get the code below generate rows and columns but the sort is messed up.

TIA

if($count%3==0) {
$array1[] = "$title<br>";
}
else if($count%3==1) {
$array2[] = "$title<br>";
}
else if($count%3==2) {
$array3[] = "$title<br>";
}

<table border="0">

<tr>
<td align="left" valign="top" width="207">

<?php if($array1) {
foreach($array1 AS $column_1) echo $column_1;
} ?></td>

<td align="left" valign="top" width="208">
<?php if(isset($array2)) {
foreach($array2 AS $column_2) echo $column_2;
}?></td>

<td align="left" valign="top" width="208">
<?php if(isset($array3)) {
foreach($array3 AS $column_3) echo $column_3;
}?></td>

</tr>
</table>

coopster

1:17 pm on Sep 22, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Why not concatenate the columns in your database query for the sole purpose of sorting the data? Would that work?