I have tried this code for count rows
JavaScript
x
$count = $this->db->query("select count(*) from cgdict where cg like '%".$search_data."%'");
echo $count;
and it gives me an error
JavaScript
Object of class CI_DB_mysqli_result could not be converted to string
Advertisement
Answer
Use num_rows()
to count function, because $count
is an array (if not null):
JavaScript
$query = $this->db->query("select * from cgdict where cg like '%".$search_data."%'");
$result = $query->result_array()
$num= $result ->num_rows();
echo $num;
Or
JavaScript
$query = $this->db->query("select count(*) as TotCount from cgdict where cg like '%".$search_data."%'");
$result = $query->result_array()
echo count($result[0]['TotCount']);
Security note
Before sending $search_data
direct to SQL query, make sure you use $this->input->post
to catch and clean from SQL injection.