3064 Posts in 865 Topics by 647 members
| Go to End | ||
| Author | Topic: | 3805 Views |
-
Re: How to Display Data Results in 2 Well Formatted Rows

15 January 2009 at 4:40am
One last silly mistake, now all works. Change Row2() to:
function Row2() {
$Total = ($this->Sponsors()->Count()) ;
$Half = ceil(($Total / 2));
return DataObject::get("SponsorPage", "", "", "", "$Half, $Total");
} -
Re: How to Display Data Results in 2 Well Formatted Rows

24 January 2009 at 5:15am Last edited: 24 January 2009 11:14am
I am trying to adapt this to three columns. I have set up my PHP thusly:
function Row1() {
$Part = ceil(($this->Articles()->Count()) / 3);
return DataObject::get("ArticlePage", "", "", "", "0, $Part");
}function Row2() {
$Part = ceil(($this->Articles()->Count()) / 3);
$Part2 = floor(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Part, $Part2");
}function Row3() {
$Total = ($this->Articles()->Count()) ;
$Part = ceil(($Total / 3));
$Break = ceil(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Break, $Total");
}
}
Row 1 displays the first third of the results. Row 3 displays the last third of the results. Row 2, however, is displaying the second third all the way to the end.Example: Let's say there are 6 items.
Row 1
Item 1
Item 2
Row 2
Item 3
Item 4
Item 5
Item 6
Row3
Item 5
Item 6Any ideas why it's breaking down like that? The calculation for $Part2 should be correct since it's the same as $Break and Row 3 is starting in the correct place. I'm not a PHP programmer so I can only assume the last parameter in the Get statement indicates "start, end"
Thanks,
Joe -
Re: How to Display Data Results in 2 Well Formatted Rows

25 January 2009 at 4:43am Last edited: 25 January 2009 4:49am
UPDATE: I figured out what my problem was. I was assuming that the last parameter meant "starting record number, ending record number" when in actuality it means "starting record number, number of records to display." It works now!
Row 2 code should read:
function Row2() {
$Part = ceil(($this->Articles()->Count()) / 3);
return DataObject::get("ArticlePage", "", "", "", "$Part, $Part");
}If you wanted to add a 4th segment, change all of the 3's to 4's and change the following:
function Row3() {
$Total = ($this->Articles()->Count()) ;
$Part = ceil(($Total / 4));
$Begin = ceil(($Part * 2));
return DataObject::get("ArticlePage", "", "", "", "$Begin, $Part");
}function Row4() {
$Total = ($this->Articles()->Count()) ;
$Part = ceil(($Total / 3));
$Begin = ceil(($Part * 3));
return DataObject::get("ArticlePage", "", "", "", "$Begin, $Total");
} -
Re: How to Display Data Results in 2 Well Formatted Rows

20 September 2011 at 8:55am
Old post, but i'll give it try...
I like the idea, but my problem is (maybe) a little more challenging.
I have my records display in alphabetical range
public function AlphabeticalItems()
{
$r = $this->getRequest()->getVar('range');
if(!$r)
{
$r = "A-D"; //default reange to show
}
list($start, $end) = explode("-",$r);
return DataObject::get("Dog","PedigreeName > '$start' AND PedigreeName < '$end'","PedigreeName ASC");
}Now i've tried to use 'AlphabeticalItems' like you used 'sponsors' but that only returns row 1 of my A-D range. It never shows row2 and offcourse it doesn't show my next ranges.
I got that since my Row1 never goes back to my function 'AlphabeticalItems'So i need to display my ranges in two columns.
Any ideas on this one?
| 3805 Views | ||
| Go to Top |


