Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » How to Display Data Results in 2 Well Formatted Rows

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 4312 Views
  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Re: How to Display Data Results in 2 Well Formatted Rows Link to this post

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

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: How to Display Data Results in 2 Well Formatted Rows Link to this post

    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

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: How to Display Data Results in 2 Well Formatted Rows Link to this post

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

  • Stefdv
    Avatar
    Community Member
    110 Posts

    Re: How to Display Data Results in 2 Well Formatted Rows Link to this post

    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?

    4312 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.