[FX.php List] Split results into two columns
Stephe Pocock
zippyaus at yahoo.com
Thu Aug 27 20:49:05 MDT 2009
Hi and thanks for the feedback
I was able to achieve the following using the code (thanks to FMWebschool).
http://pastebin.com/m7794b15e
<?php
$cols = 2; // Change value for any number of columns
$cell = 0;
foreach($catResult['data']as $key=>$catData){
if( ($cell % $cols) == 0 ) { echo "<tr>\n"; }
?>
<td height="42"><img src="<?php echo $catData['PhotoURL'][0];?>" width="120"></td>
<td><?php echo $catData['Full Name'][0];?><br>
<?php echo $catData['UserName'][0];?><br>
<?php echo $catData['Export Title'][0];?><br>
<?php echo $catData['Level Number'][0];?> <?php echo $catData['Calc Group Short'][0];?></td>
<?php
if( (($cell+1) % $cols) == 0 ) { echo "</tr>\n"; }
$cell++;
} ?>
Hope this helps someone.
Cheers
________________________________
From: Jonathan Schwartz <jschwartz at exit445.com>
To: FX.php Discussion List <fx.php_list at mail.iviking.org>
Sent: Thursday, 27 August, 2009 10:17:45 PM
Subject: Re: [FX.php List] Split results into two columns
Re: [FX.php List] Split results into two
columns
I think the key (no pun) is to create the content first and then
display when done.
How about this:
Option 1:
Process the found set with the standard foreach(), test for
odd/even records, build the even and odd record tables first and then
display them after they are complete.
Option 2:
Process the found set with a for(), alternating left and right
columns by testing for even/odd $key, building them first and then
displaying, as above.
This is just the broad stroke.
J
Hi all
>
>>I have a confession to make. I use this code alot, but I don't
>actually understand how it works.
>
>http://pastebin.com/m7cb20894
>
>><?php
>>$i=0;
>>$half = (int) ($catResult['foundCount']/2 + 0.5);
>
>>foreach ($catResult['data'] as $key => $catData)
>>{
>>if($i == $half && $i > 10)
>>{
>>?>
>>
></table>
>> <td valign="top">
>>
><table border="1">
>><?php
>>}
>
>>?>
>> <tr>
>> <td>
>>
><img src="<?php echo $catData['PhotoURL'][0];?>"
>width="120"></td>
>> <td><?php echo
>$catData['Full Name'][0];?><br>
>> <?php echo
>$catData['UserName'][0];?><br>
>> <?php echo
>$catData['Export Title'][0];?><br>
>> <?php echo
>$catData['Level Number'][0];?> <?php echo $catData['Calc Group
>Short'][0];?>
>> </td>
>>
>
>> </tr>
>><?php
>>$i++;
>>}
>>}
>>?>
>
>
>
>>The result is half the found set is in one table row that the other
>half in another.
>
>>This works well in most situations, but I have a photobook where I
>want two columns but I would like the odd records in the left and the
>even records in the right so that the photo book flows with all the
>A's then all the B's etc
>
>>Does this make sense? Is what I want possible?
>
>>Thanks in advance
>
>>Stephen
>
>>start: 0000-00-00 end: 0000-00-00
________________________________
Find local businesses and services in
>your area with Yahoo!7 Local. Get started.
>>_______________________________________________
>>FX.php_List mailing list
>>FX.php_List at mail.iviking.org
>http://www.iviking.org/mailman/listinfo/fx.php_list
--
Jonathan Schwartz
Exit 445 Group
jonathan at exit445.com
http://www.exit445.com
415-370-5011
__________________________________________________________________________________
Find local businesses and services in your area with Yahoo!7 Local.
Get started: http://local.yahoo.com.au
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.iviking.org/pipermail/fx.php_list/attachments/20090827/0b0e32c2/attachment-0001.html
More information about the FX.php_List
mailing list