Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2005-05-13, 01:13 PM   #1
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
generally I use modulo or % to do this.

basically, set your $loop = 0;

if ($loop % 7) { print "</tr><td>" }

$loop modulo 7 = 0 when there is no remainder, i.e., the column is divisible by 7 (or if the loop is 0) You need to do some special case handling for 0, and some end of loop processing if there aren't a multiple of 7 columns in your result set.

The reason for your extra column is probably that you started loop at 1, and are dividing by 7, which gives you a first blank column -- then things should realign themselves unless there is something else I'm not seeing. From what you posted, you should get 6 columns in the first row, 7 in each successive row.

Another way is to use an indexed array and use two for loops...

Code:
print "<table>";
for ($loop=0;loop<$numcols;loop+=7) {
  print "<tr>";
  for ($loop2=$loop;$loop2<$loop+7;$loop2++) {
    print "<td>asdfa</td>";
  }
  print "</tr>";
}
print "</table>";
Many different ways to handle tabular data.... and they all boil down to a simple control-break structure.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2005-05-13, 03:48 PM   #2
Barron
You tried your best and you failed miserably. The lesson is 'never try'
 
Join Date: Oct 2004
Posts: 166
Your right, I may end up changing the routine to a nested loop of some kind to catch the end of the list.

Your example brings to mind something I've been wanting to ask someone for a long time.

I read a post on php.net about 2 years ago I think, where some guy benchmarked, do, for, foreach and while. The slowest was for when it came to speed and do being the fastest. If I remember correctly do is 60% faster than for. Since then, I stopped using for statements unless dealing with very small arrays. I try to trim off any excess load that I can.

Have you noticed any speed difference between any of these?


-
Barron is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:46 PM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc