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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

How to return only one value from Dataobject if data in different data sets are indentical


Reply

3 Posts   591 Views

Avatar
LarsE

27 August 2012 at 10:10am Community Member, 8 Posts

Hi there,

hope I can explain my problem clearly. Okay, I will try..
I have created a dataobject with data sets like this:

1. data set: name1 - adress1 - town1
2. data set: name2 - adress2 - town1
3. data set: name3 - adress3 - town2
4. data set: name4 - adress4 - town2
3. data set: name5 - adress5 - town3

You can see that different people are living in different towns.

Now I would like to know in which different towns the people are living.

The desired result should be: town1, town2 and town3

Any ideas? Thanks everybody for support,

Lars

Avatar
SparkGreen

27 August 2012 at 11:40am Community Member, 6 Posts

If you start with a GROUP BY sql statement:

$sql = singleton('SomeObject')->buildSQL();
$sql->select[] = "town";
$result = $sql->groupby("town")->execute();

And then pass the result into a dataobject you can use:

$groupObject = singleton('SomeObject')->buildDataObjectSet($result);

Just return $groupObject and you can use it in your template.

Avatar
LarsE

27 August 2012 at 10:32pm Community Member, 8 Posts

Hi SparkGreen,

thank you so much. Your job works perfectly!
Best regards,

LarsE