TP随机从数据库中获取一条数据

orderRaw('rand()');
    /**
     * 随机获取一条商品信息
     * @param [type] $condition
     * @param [type] $field
     * @param [type] $limit
     * @return void
     */
    public function randSkuid($condition, $field, $limit)
    {
        $result = $this->where($condition)->field($field)->orderRaw('rand()')->limit($limit)->select();
        return $result ? $result->toArray() : [];
    }

 

猜你喜欢

转载自www.cnblogs.com/camg/p/11986618.html