亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

調用未定義的方法 CodeIgniter\Database\MySQLi\Builder

調用未定義的方法 CodeIgniter\Database\MySQLi\Builder

PHP
有只小跳蛙 2023-09-15 18:36:08
我正在嘗試為我的表制作一個代碼生成器這是我的模型:public function buat_kode()   {    $this->db->table('RIGHT(proses_cutting.kode_packing_list,6) as kode', FALSE);    $this->builder()->orderBy('kode_packing_list','DESC');        $this->builder()->limit(1);          $query = $this->db->table('proses_cutting');      //cek dulu apakah ada sudah ada kode di tabel.          if ($query->num_rows() <> 0){             //jika kode ternyata sudah ada.              $data = $query->row();              $kode = intval($data->kode) + 1;          }      else {             //jika kode belum ada              $kode = 1;          }      $kodemax = str_pad($kode, 6, "0", STR_PAD_LEFT); // angka 4 menunjukkan jumlah digit angka 0      $kodejadi = "PLIK059".$kodemax;    // hasilnya ODJ-9921-0001 dst.      return $kodejadi;    }控制器 :public function create(){    session();    $data = [        'main' => 'prosescutting/create',        'validation' => \Config\Services::validation(),        'title' => 'Form Tambah Proses Cutting',        'kodeunik' => $this->pcuttingModel->buat_kode(),        'kode_packing_list' => $kodePackingSekarang,    ];    return view('template/template', $data);}和我的桌子: 桌子我想做的是為 nama_barang 的每個項目制作一個 kode_packing_list 生成器,這樣當我輸入另一件 Renata Blouse 時,它會自動填充PLIK059000007但是當我嘗試運行它時,它向我顯示了以下錯誤:錯誤調用未定義的方法 CodeIgniter\Database\MySQLi\Builder::num_rows() APPPATH\Models\PcuttingModel.php 第 33 行第 33 行是if ($query->num_rows() <> 0){  
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

您使用了錯誤的數據庫表函數,請嘗試以下操作:


$db = \Config\Database::connect(); // optional; init database if not created yet


$builder = $db->table('proses_cutting');

$builder->select('RIGHT(proses_cutting.kode_packing_list,6) as kode');

$builder->orderBy('kode_packing_list','DESC');

$builder->limit(1);


if($builder->countAllResults() > 0) {

? ? $query = $builder->get();

? ? $result = $query->getResult(); // Result as objects eg; $result->kode

? ? $kode = $result->kode;

}


// Other option: I believe you can do this too


$builder = $db->table('proses_cutting');

$builder->select('RIGHT(proses_cutting.kode_packing_list,6) as kode');

$builder->orderBy('kode_packing_list','DESC');

$builder->limit(1);


$query = $builder->get();

$result = $query->getResult('array');

if(is_array($result) && count($array) > 0) {

? ? $kode = $result['kode'];

}

查看完整回答
反對 回復 2023-09-15
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號