我有一個 codeigniter 網站,我試圖根據用戶 ID 和日期顯示一些結果,
我的資料庫如下:

我有一個這樣的日期,將由用戶選擇:2022-04-08
我想要的是從那個完整月份的表中獲取所有資料,如果我得到一個日期,我想獲取整個月份。
我做了這樣的事情:
public function selectview($id,$date)
{
$this->db->select('*');
$this->db->from('delivered');
$this->db->where("cid", $id);
$this->db->like('date', $date, 'after');
$query = $this->db->get();
$result = $query->result();
return $result;
}
但是這并沒有給出那個月的所有日期,誰能告訴我如何完成這個,提前謝謝
uj5u.com熱心網友回復:
您需要修改$date為year和month。嘗試這樣的事情:
public function selectview($id,$date)
{
//assuming your date format is YYYY-MM-DD
$newDate = substr($date,0, strrpos($data, "-")); // 2022-04
$this->db->select('*');
$this->db->from('delivered');
$this->db->where("cid", $id);
$this->db->like('date', $newDate); //pass new date here
$query = $this->db->get();
$result = $query->result();
return $result;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/456361.html
