Jump to:

3447 Posts in 1032 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Control Break Processing?

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

Page: 1
Go to End
Author Topic: 1055 Views
  • _Vince
    Community Member
    161 Posts

    Control Break Processing? Link to this post

    Hi, I hope this is the right section

    Say I have a pet shop, and I have the following table.

    species breed
    ===== =====
    Dog Poodle
    Dog Labrador
    Dog Pekinese
    Dog Dalmatian
    Cat Persian
    Cat Tabby

    and I want to display the table contents on a web page.

    I'd like to have a big heading every time the species changes, something like



    is there any way of doing this?

    I know a way of doing it in MySQL but I also have an image for each animal, and I want to be able to do stuff like setWidth and so on. If I do a SQLQuery() I will lose that functionality.

    I've also tried to merge two DataObjects but then I get the same records twice, once with the images, once without.

    Any ideas?

  • _Vince
    Community Member
    161 Posts

    Re: Control Break Processing? Link to this post

    In the end, I adapted this from a reply I found on a MySQL forum.

          $sqlQuery = new SQLQuery();
          $sqlQuery->select = array(
             "@anum := if(@SubCategory = SubCategory, @anum + 1, 1) as row_num",
             "@SubCategory := SubCategory as dummy"
          $sqlQuery->from = array("(SELECT @anum:=0) r,
             (SELECT @SubCategory:='') c, Products p");

    $result = $sqlQuery->execute();

          $Products = new DataObjectSet();

          foreach($result as $row) {
             $Products->push(new ArrayData($row));
          return $Products;

    it returns a running sequence number for rows within the same subcategory.

    And if I know the row number, I can go to the template and say

    <% if row_num=1 %>
    Do big heading
    <% end_if %>

  • ajshort
    Community Member
    244 Posts

    Re: Control Break Processing? Link to this post

    There's a much nicer way of grouping records inbuilt into SilverStripe - see here for more information

  • _Vince
    Community Member
    161 Posts

    Re: Control Break Processing? Link to this post

    That IS nice!

    Is there a way of having more than one child group?

    At the moment it does


    whereas I need something like


Page: 1
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.