Propel Random Criteria >>

$c= new Criteria(); $c->addAscendingOrderByColumn('rand()'); $TagRs = TagPeer::doSelect($c ); ?>

This code will give you the result in random manner. Here in this example, i show the random tags from Tag Table.

Propel Memory Optimization using Result Set >>

if you use

$TagRs= TagPeer::doSelect(new Criteria());

The whole result of the query will be saved in $TagRs as array (Means usage of memory to save whole the table rows).
But if you want two columns of this table, the rest are wastage of memory. In that case you can use result set after selecting the
desired columns.


$c = new Criteria(); $c->addSelectColumn(FilePeer::FILETAG); $c->addSelectColumn(FilePeer::TITLE); $FileRs = FilePeer::doSelectRS($c); foreach($FileRs as $FileR) { $Tag = $FileR[0]; // Here the first column is the tag $Title= $FileR[1]; //Second column is the title }

Here you saves the memory, since $FileRs contains only two columns information.

Propel Set Limit >>

If you want to set a limitation for your query results, you can use setLimit function.


$c = new Criteria(); $c->setLimit(10); $FileRs = FilePeer::doSelectRS($c);

Here the Array $FileRs only contains 10 records. Thus you can limit the query results.

Propel Set Offset >>

If you want the results of a particular query , from a cetain offset, you can use offset function.


// Select Random 3 images

$random = rand(0,$TotalCountImages); $c=new Criteria(); $c->addDescendingOrderByColumn(FilePeer::ID); $c->add(FilePeer::APPROVED,-1,Criteria::NOT_EQUAL); $c->add(FilePeer::FTYPE,'IMAGE' ); $c->setOffset($random); $c->setLimit(3); $RelatedRs = FilePeer::doSelect($c);

//Here the relatedRs will start from a random offset. (Not from the begining as usual query results)