catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

how to use:ORDER BY rand() #249

Closed woxiangfy closed 6 years ago

woxiangfy commented 9 years ago

I want to use:ORDER BY rand(); so I edit:

if (isset($where['ORDER'])) { $rsort = '/(^[a-zA-Z0-9-.])(\s_(DESC|ASC))?/'; $ORDER = $where['ORDER'];

if (is_array($ORDER))
{
    //code....
}
else
{
    if ($ORDER == 'rand()') {
        $where_clause .= ' ORDER BY rand()';
    } else {
        preg_match($rsort, $ORDER, $order_match);

        $where_clause .= ' ORDER BY "' . str_replace('.', '"."', $order_match[1]) . '"' . (isset($order_match[3]) ? ' ' . $order_match[3] : '');
    }
}

}

any other solutions?

catfan commented 6 years ago

Check out the new feature raw object https://medoo.in/api/raw.