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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

get random object


Go to End


4 Posts   3824 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 :/