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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

get random object


Go to End


4 Posts   4402 Views

Avatar
snaip

Community Member, 181 Posts

16 March 2009 at 1:28am

Edited: 16/03/2009 2:37am

i need to get 4 random objects from database

    $Randomelements = DataObject::get(
      $callerClass = "PLWycieczkaPage",
      $filter = "Display = 'ON'",
      $sort = "",
      $join = "",
      $limit = 4 
    );
    return $Randomelements;

how to add RAND() to this code ?

sec question

how to execute in the same time two objects ?

    $Staticelements = DataObject::get(
      $callerClass = "ENWycieczkaPage",
      $filter = "Display = 'always'",
      $sort = "",
      $join = "",
      $limit = "" 
    );
    return $Staticelements;


    $Randomelements = DataObject::get(
      $callerClass = "PLWycieczkaPage",
      $filter = "Display = 'sometimes'",
      $sort = "",
      $join = "",
      $limit = 4 
    );
    return $Randomelements;

in this way only "return $Staticelement" works but it stop executing "return $Randomelements"

Avatar
snaip

Community Member, 181 Posts

16 March 2009 at 11:21pm

??

Avatar
snaip

Community Member, 181 Posts

17 March 2009 at 1:48am

Edited: 17/03/2009 1:49am

AD 2)

$doSet1->merge($doSet2);
return $doSet1;

what about RAND() function in DataObject::get ?

Avatar
snaip

Community Member, 181 Posts

17 March 2009 at 2:11am

$Randomelements = DataObject::get(
$callerClass = "PLWycieczkaPage",
$filter = "Display = 'sometimes'",
$sort = "RAND()",
$join = "",
$limit = 4
); 

ehhhh :/