PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 4, 2022

[FIXED] searchbox in codeigniter giving blank data

 March 04, 2022     codeigniter, controller, model, mysql, php     No comments   

Issue

i have a simple searchbox in codeigniter, the controller is like below:

function searchtrack() {
    $this->load->model('excel_import_model');
    if(isset($_POST['submittrack'])) {
        $awb=$this->input->post('awb');
        $data['slt']= $this->excel_import_model->searchtrack($awb);
        $this->load->view("searchtrack",$data);
    }
}
}

the model is like below:

public function searchtrack($awbno) {
    $this->db->select('*');
    $this->db->where("awb", $awbno);
    $this->db->from('consignments');
    $query = $this->db->get();
    $result = $query->result();
    return $result;
}

and finally the display view:

<?php
  foreach($slt as $val){ echo $val->id; }
?>

however this not giving me any values, the post input is getting passed to the controller and the database column and all is fine, can anyone please tell me what is wrong in here thanks in advance


Solution

In your model, replace "where" with "like". "Where" look for specific data where "like" look for similar data.

public function searchtrack($awbno) {
    $this->db->select('*');
    $this->db->like("awb", $awbno, 'both');
    $this->db->from('consignments');
    $query = $this->db->get();
    $result = $query->result();
    return $result;
}

To control where the wildcard (%) placing in "like" method, a third parameter is used.

$this->db->like('awb', $awbno, 'before');    // Produces: WHERE `title` LIKE '%match' ESCAPE '!'
$this->db->like('awb', $awbno, 'after');     // Produces: WHERE `title` LIKE 'match%' ESCAPE '!'
$this->db->like('awb', $awbno, 'none');      // Produces: WHERE `title` LIKE 'match' ESCAPE '!'
$this->db->like('awb', $awbno, 'both');      // Produces: WHERE `title` LIKE '%match%' ESCAPE '!'


Answered By - mail2bapi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing