php - 如何在PHP中按列递增和显示调用随机记录? (Codeigniter)

标签 php mysql codeigniter

我想用随机数据调用php中的database,但仍然显示在stock的首页,而没有stock的底页。
我对用这种方式调用代码感到困惑。
当我用这个打电话的时候

$this->db->order_by('stock_pro','desc','RAND()');

什么都没发生。
我用的是框架CodeigniterBootstrap
这个myfunction
public function list_sale(){
        $this->db->select('products_order.*, category, slug_category');
        $this->db->from('products_order');
        $this->db->join('category', 'products_order.category = category.id', 'left');
        //$this->db->order_by('RAND()');
        $this->db->order_by('stock_pro','desc');
        $this->db->where('category.disc > 0' );
        $query = $this->db->get();
        return $query->result();
    }

最佳答案

使用我的代码。
当我自己测试代码时。它的作品。
我不知道你的测试是否真的有效。对于table,您的列在tabledisccategory中感到困惑,请务必阅读注释。

public function list_sale(){
        $this->db->select('products_order.*, category, slug_category');
        $this->db->from('products_order');
        $this->db->join('category', 'products_order.category = category.id', 'left');
        $this->db->where('stock_pro > 0');
        //$this->db->where('products_order.disc NOT LIKE 0'); //if table products_order turn off comment
        //$this->db->where('category.disc NOT LIKE 0'); //if table category turn off comment
        $this->db->order_by('RAND()');
        $query = $this->db->get();
        return $query->result();
    }

因为你的任务不能同时使用随机和升序(我不知道,因为我没有找到代码你的问题是什么)。
如果需要,可以使用此代码,再创建一个products_order用于缺货和调用另一个function代码,该代码放在查看页面的底部代码中,即调用库存产品中的视图。

关于php - 如何在PHP中按列递增和显示调用随机记录? (Codeigniter),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57900900/

相关文章:

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

php - 非法 0000-00-00 00 :00:00 timestamp being sent by php to mysql using codeigniter

mysql - 在 MySQL 4.0 中同时具有 Created 和 Last Updated 时间戳列

php - PHP 中 WHERE 后的多列?

mysql - SELECT WHERE IN(子查询)慢

javascript - 将动态图像与 HTML5 WebGL 360 度全景查看器与 Codeigniter 中的 Three.js 集成

php - 为什么 PHP 在[宽松地]比较两个数字字符串之前将它们转换为数字?

php - 使用 laravel 5 在表上创建一个新的字符串列

php - 如何使用 PHP 和 Codeigniter 处理 foreach 中 mysql 中的 SELECT(MAX())

php - Codeigniter 中的 HTML 格式的电子邮件