Search code examples
phpormredbean

RedBeanPHP: Values in Find don't work


I used the example below to order the results in my Table however the orderby variable doesn't seem to effect the order of results. I can't get access to the underlying SQL Query to see what RedBean is doing and I have checked and $sortorder and $sort are the correct values.

$needles = R::find('needle',
    ' haystack = :haystack ORDER BY :sortorder :sort', 
        array( 
            ':sort' => $sort
            ':sortorder'=>$sortorder, 
            ':haystack'=>$haystack 
        )
    );

Solution

  • But, you can easily prepare your query string before :

    $query = sprintf('ORDER BY %s %s LIMIT :size', $column, $sortOrder);
    
    $items = R::find(
        'item',
        $query,
        array(
            'size' => (int) $size
        )
    );