Rank checkboxes vertical ASC

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
Collab
Forum Newbie
Posts: 9
Joined: Mon Oct 06, 2008 11:11 pm

Rank checkboxes vertical ASC

Post by Collab »

Hi all,

Is it possible to rank a list of values in three columns in alphabetical order when outputting them as a checkbox list?

In other words: say I have a list of 12 values, and I would like to list them in three columns (always three columns) and I would like them listed alphabetically in a vertical way. Now, they are ranked, but horizontally. Is there an 'easy' way or not really?

Example:
Much like:
a - d - g
b - e - h
c - f - i

Instead of:
a - b - c
d - e - f
g - h - i
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Rank checkboxes vertical ASC

Post by requinix »

How easy is it depends on where the checkboxes are coming from. Simplest method would be if you have an array.

Say the array has X items in it. If you want them in three columns then there will be at most N=ceil(X/3) in each column: first column has 0 through (N-1), second column has N through (2N-1), third column has 2N through the end.

Since HTML works in a top-down fashion you need to print everything one row at a time (assuming you're using a table). The first row has #0, #N, and #2N. Second row has #1, #N+1, and #2N+1. Goes all the way until you're near the bottom of the table: the third column might not be complete so you need to check whether the item exists before trying to get it.

Should be enough to get you started.
Post Reply