[thelist] Multiple columns - howto?

Kae Verens kverens at contactjuggling.org
Wed Feb 19 02:40:01 CST 2003


Anthony Baratta wrote:
> At 05:35 PM 2/18/2003, Anthony Baratta wrote:
>
>> pseudo code alert
>>
>> colNmbr = 1
>> colCount = 3
>> strQuery = "Select Blah Blah Blah"
>> Execute Query
>> while we have data
>>     strRow = db.DataField
>>     if colNmbr = 1 then
>>        PrintOut "<tr><td>" . strRow . "</td>"
>>        colNmbr ++
>>     else
>>        PrintOut = "<td>" . strRow . "</td>"
>>
>>     if colNmbr = colCount
>>        PrintOut = "<td>" . strRow . "</td></tr>"
>>        colNmbr = 1
>> end while
>
>
> For got to add a check for closing up the table properly...
>
> if colNmbr > 1 &&  colNmbr != colCount
>   while colNmbr < colCount
>      PrintOut "<td>&nbsp;</td>"
>      colNmbr ++
>      if colNmbr = colCount
>         PrintOut "</tr>"
>   end while

This version uses the modulus operator to check whether a field is at
the beginning or end of a row:

$cols=3;
$x=0;
?><table><?
while($r=mysql_fetch_array($query)){
  if(!($x%$cols)){?><tr><?}
  ?><td><?=$r['fields'];?></td><?
  if(!(($x-1)%$cols)){?></tr><?}
  $x++;
}
if($x%$cols){
  while($x%$cols){?><td>&nbsp;</td><?$x++;}
  ?></tr><?
}
?></table><?

--
Kae Verens               _______\_   webworks.ie
work: www.webworks.ie       _____\\__   webhosts
play: www.contactjuggling.org  ___\\\___  design
kae:  kverens.contactjuggling.org _\\\\____ code




More information about the thelist mailing list