3217 Posts in 853 Topics by 812 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 898 Views |
-
Control Break Processing?

24 September 2010 at 12:33pm Last edited: 24 September 2010 12:34pm
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
DOG
===
Poodle
Labrador
Pekinese
DalmatianCAT
===
Persian
Tabbyis 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?
-
Re: Control Break Processing?

25 September 2010 at 3:11pm
In the end, I adapted this from a reply I found on a MySQL forum.
$sqlQuery = new SQLQuery();
$sqlQuery->select = array(
"p.*",
"@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");$sqlQuery->orderBy("CategoryID,SubCategory");
$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 %> -
Re: Control Break Processing?

25 September 2010 at 5:51pm
There's a much nicer way of grouping records inbuilt into SilverStripe - see here for more information
-
Re: Control Break Processing?

28 September 2010 at 2:31pm
That IS nice!
Is there a way of having more than one child group?
At the moment it does
pets->dogs
whereas I need something like
products->pets->dogs
| 898 Views | ||
|
Page:
1
|
Go to Top |


