At 11/16/2006 12:19 PM, Ashley M. Kirchner wrote:

Say I have an array containing ten items, and I want to display them in a table as follows:

    5 4 3 2 1
   10 9 8 7 6

What's the best way to loop through that array to do that? My thinking gets me to create a loop for 5 through 1, repeated twice, and the second time I add '5' to the index value. There's got to be a saner way...


In order to figure out the best PHP logic to generate the series, I'd first make sure the markup is solid. I realize that you've already indicated a table markup in two rows, but I'd like to examine that. Can you tell us why the numbers are in this particular sequence?

Do the numbers represent items that are conceptually in ascending order but are presented in reverse order on the screen? If so, I'd wonder whether someone reading the page with assistive technology might be confused by the reverse order, and I'd try to find a way to mark them up ascending and then change the sequence stylistically.

Are they split into two rows because they represent two discrete groups in the data set or because of display considerations? If the latter, I'd argue that they don't really belong in two table rows; that using tables to force presentation is misapplying the tool.

Have you considered an unordered list, floated right, wrapped in a container whose width naturally forces a wrap after the fifth item? I like that solution because it allows you to mark up the numbers in sequence and in future change the number of items in the sequence and/or change the way the series is presented visually without having to mess with the logic generating the markup.

Regards,
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to