簡體   English   中英

我如何使用查詢生成器 function 從具有 WHERE 條件和 desc 順序的表中獲取 Select?

[英]how do i Select from table with WHERE condition and desc order using query builder function?

我正在嘗試在我的評論表中添加 select 評論。 我想使用 codeigniter 3 個查詢構建器函數根據報告編號並按降序排列它們,我該怎么做?

我在我的 model 中得到了這個代碼,如果我 var_dump 它就不能按照我想要的方式工作。 這是我到目前為止的代碼:

    $this->db->order_by('Date', 'DESC');
    $query=$this->db->where("Comments", array('ReportNum' => $report));
    $row=$query->result();

這是我在 var_dump 時得到的:

object(CI_DB_mysqli_result)#27 (8) { ["conn_id"]=> object(mysqli)#16 (18) { ["affected_rows"]=> int(5) ["client_info"]=> string(13) " mysqlnd 8.0.9" ["client_version"]=> int(80009) ["connect_errno"]=> int(0) ["connect_error"]=> NULL ["errno"]=> int(0) ["error" ]=> string(0) "" ["error_list"]=> array(0) { } ["field_count"]=> int(5) ["host_info"]=> string(25) "Localhost via UNIX socket" ["info"]=> NULL ["insert_id"]=> int(0) ["server_info"]=> string(21) "5.5.5-10.4.20-MariaDB" ["server_version"]=> int( 100420) ["sqlstate"]=> string(5) "00000" ["protocol_version"]=> int(10) ["thread_id"]=> int(571) ["warning_count"]=> int(0) } ["result_id"]=> object(mysqli_result)#26 (5) { ["current_field"]=> int(0) ["field_count"]=> int(5) ["lengths"]=> NULL ["num_rows "]=> int(5) ["type"]=> int(0) } ["result_array"]=> array(0) { } ["result_object"]=> array(5) { [0]=>對象(stdClass)#28(5 )

^ 這在所需的數組之前。

您需要一個 get 子句來查詢表,您可以使用:

在哪里():

$this->db->order_by('Date', 'DESC');
$this->db->where( array('ReportNum' => $report));
$query=$this->db->get("Comments");
$row=$query->result();

或使用 get_where():

$this->db->order_by('Date', 'DESC');
$query=$this->db->get_where("Comments", array('ReportNum' => $report));
$row=$query->result();

關於CI 3.x 查詢生成器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM