Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

How to Display Data Results in 2 Well Formatted Rows


Go to End
Reply


12 Posts   4514 Views

Avatar
Andrew Houle

Community Member, 133 Posts

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");
   }

Avatar
jfusco

Community Member, 52 Posts

24 January 2009 at 5:15am

Edited: 24/01/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 6

Any 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

Avatar
jfusco

Community Member, 52 Posts

25 January 2009 at 4:43am

Edited: 25/01/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");
}

Avatar
Stefdv

Community Member, 110 Posts

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?

Go to Top