By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,481 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,481 IT Pros & Developers. It's quick & easy.

displaying single column data in multiple columns

P: 26
This might seem like a problem with a simple solution, but I'm not entirely sure how to approach it.

I would like to generate a user contact list from a table of user details on a database. However, for the master page (which only needs to display the name), I was wondering if there is any way that the user names could be displayed in multiple rows rather than one continuous vertical stream (I would rather avoid recordset paging).

I suppose you could do it horizontally by outputting each record in a css block element one third of the total div width, but I would rather do it in a vertical direction ie you go down, then start at the top and once again for a 3 column list.

Any pointers in the right direction would be appreciated.
Aug 6 '07 #1
Share this Question
Share on Google+
4 Replies


kovik
Expert 100+
P: 1,044
?

Maybe... a table...?
Aug 7 '07 #2

P: 26
sorry, maybe I wasn't clear enough -

yes, I could use a table, but what I'm not sure is how to do the looping structure in order to go down vertically ie

Item 1 - Item 4 - Item 7
Item 2 - Item 5 - Item 8
Item 3 - Item 6 - Item 9

Presumably you need some sort of auto-increment counter to decide where to draw <tr> and <td>? Or create two divs and assign recordsets to $col1 $col2 and $col3?

My main problem is that the total number of contacts can vary, so the number per column will be the total no. of contacts / 3...

Is this possible or should I just try and go for a horizontal order
Item1 - Item 2 - Item3 etc
?
Aug 7 '07 #3

kovik
Expert 100+
P: 1,044
[php]echo '<table><tr>';
$i = 0;

while($data = mysql_fetch_object($result))
{
$i++;

if(($i % 3) == 0)
{
$i = 0;
echo '</tr><tr>';
}

echo '<td>' . $data->foo . '</td>';
}

echo '</tr></table>';[/php]

Maybe?
Aug 7 '07 #4

P: 26
yes, that's along the lines of what I'm looking for - wasn't quite sure about the exact syntax with counter divisions, but adapting this has worked. thanks.
Aug 9 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.