Welcome Guest, Not a member yet? Register   Sign In
can someone help me change function to run codeigniter 4 ?
#1

(This post was last modified: 01-25-2022, 02:52 AM by startup.)

i have two function below:
1.
PHP Code:
public function vlChos(){
        $query "SELECT id, name FROM categories WHERE parent_id = '429' ";
          $query=$this->db->query($query);
          return $query->getResultArray();
        
function 1  working in codeigniter 4

function 2
PHP Code:
public function vlDemo(){
        $this->db->select('id,name');
        $this->db->where('parent_id','429');
        $q=$this->db->get('categories');
        $rs=$q->getResult();
        return $rs;
        

function 2 dont working in codeigniter 4,

can someone help me rewrite function 2 to working in codeigniter 4 ?

thank you in a advance

note for newbaby to start learn codeigniter 4 like me

we use builder to connect  to database
PHP Code:
public function vlDemos(){
        $builder $this->db->table("categories");
        $builder->select('id,name');
        $builder->where('parent_id','429');
        $query $builder->get();
        return $query->getResult();
        

i write this function , code perfect in codeigniter

stop help thank you very much
Reply
#2

Glad that you figured that out, but that's how i would write it


PHP Code:
public function vlDemos(int $parent_id 429){
  return $this->db->table('categories')
              ->select('id, name')
              ->where('parent_id'$parent_id)
              ->get()
              ->getResult();

Reply




Theme © iAndrew 2016 - Forum software by © MyBB