获取表中随机数的方式

Posted wntd

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取表中随机数的方式相关的知识,希望对你有一定的参考价值。

1、可以使用rand去随机表id字段

2、可以使用array_rand函数去随机获取到的数据

/**
 * 获取随机的快递单号
 * @return mixed
 */
function get_order_invoice_no(){

    //获取没有分配的快递单
    $sql = "SELECT order_invoice_no_id,invoice_no FROM order_invoice_no WHERE is_used = 0";

    $invoice_nos = $GLOBALS[‘db‘]->getAll($sql);

    $key=array_rand($invoice_nos);

    $good_ids = $invoice_nos[$key];

    return $good_ids;
}

  

 

以上是关于获取表中随机数的方式的主要内容,如果未能解决你的问题,请参考以下文章