07-19-2011, 08:43 AM
[eluser]ACEFX[/eluser]
I have been struggling with this code for days now.
I want to pass a query to a library and run it in the library but once i pass the query, i get this
Message: Object of class CI_DB_mysql_result could not be converted to string
Here is the model that calls it
And the library
Please i need this help urgently, can someone help me out, this is running me totally crazy
Thanks
I have been struggling with this code for days now.
I want to pass a query to a library and run it in the library but once i pass the query, i get this
Message: Object of class CI_DB_mysql_result could not be converted to string
Here is the model that calls it
Code:
$this->load->library('util');
$pagin['rows'] = 200;
$pagin['table'] = 'adminregister';
$pagin['qt'] = 3;
$pagin['where'] = '';
$pagin['query'] = 'SELECT * FROM `adminregister` WHERE `ACALVL` = 25';
$pagin['direction'] = 'next';
$datax = $this->util->paginator($pagin);
return $datax;
And the library
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Util{
function __construct(){
$CI =& get_instance();
//load libraries
$CI->load->database();
$CI->load->library("session");
}
//PAGINATION FUNCTION
function paginator($pagin){
$CI =& get_instance();
$p_row = $pagin['rows'];
$p_tab = $pagin['table'];
$p_qt = $pagin['qt'];
$p_dir = $pagin['direction'];
$p_whr = $pagin['where'];
$p_qry = $pagin['query'];
//Check for session or reset Session
if(!isset($p_row) || $p_row != $CI->session->userdata('PROW')){
$this->clrpagin();
//SET NEW SESSION
$CI->session->set_userdata('PROW', $p_row);
$CI->session->set_userdata('PTAB', $p_tab);
$CI->session->set_userdata('PQT', $p_qt);
}else if(!isset($p_tab) || $p_tab != $CI->session->userdata('PTAB')){
$this->clrpagin();
//SET NEW SESSION
$CI->session->set_userdata('PROW', $p_row);
$CI->session->set_userdata('PTAB', $p_tab);
$CI->session->set_userdata('PQT', $p_qt);
}else if(!isset($p_qt) || $p_tab != $CI->session->userdata('PQT')){
$this->clrpagin();
//SET NEW SESSION
$CI->session->set_userdata('PROW', $p_row);
$CI->session->set_userdata('PTAB', $p_tab);
$CI->session->set_userdata('PQT', $p_qt);
}
//Session for currentpg
$cntx = $CI->session->userdata('rowcount');
if(!isset($cntx) || $cntx != 1){
$cnt = 0;
}else{
$cnt = 1;
}
$curpg = $CI->session->userdata('currentpg');
if(!isset($curpg) || !is_numeric($curpg)){
//echo 'This is'.$CI->session->userdata('currentpg'); exit();
$curpg = 0;
}else{
//NEXT BUTTON
if($p_dir == 'next'){
$curpg = $curpg + $p_row;
}else if($p_dir == 'prev'){
$curpg = $curpg - $p_row;
if($curpg < 0){
$curpg = 0;
$CI->session->set_userdata('currentpg', $curpg);
$CI->session->set_userdata('btnhide', 'prev');
return 'mn';
}
}
}
//echo $curpg; //exit();
//GET ALL DATA
if($p_qt == 1){ //Normal Get
if($cnt == 0){ //Count number of rows in Table
$rowcount = $CI->db->count_all($p_tab);
$CI->session->set_userdata('rowcount', $rowcount);
}
//Stop proccess for more than total count
if($curpg > $rowcount){
return 'mx';
}
$CI->db->limit($p_row, $curpg);
$que= $CI->db->get($p_tab);
}
//GET ALL DATA WITH WHERE CLAUSE
else if($p_qt == 2){ //get_where
$CI->db->where($p_whr);
if($cnt == 0){ //Count number of rows in Table
$rowcount = $CI->db->count_all($p_tab);
$CI->session->set_userdata('rowcount', $rowcount);
}
//Stop proccess for more than total count
if($curpg > $rowcount){
$CI->session->set_userdata('btnhide', 'next');
return 'mx';
}
$CI->db->limit($p_row, $curpg);
$que= $CI->db->get($p_tab);
}
//GET DATA BASED ON QUERY
else if($p_qt == 3){ // custom query
if($cnt == 0){ //Count number of rows in Table
$rowcount = $CI->db->query($p_qry); //If the query is not quoted, then there will be object error
$totalresp = $this->$rowcount->num_rows();
$CI->session->set_userdata('rowcount', $totalresp);
}
//Stop proccess for more than total count
if($curpg > $rowcount){
$CI->session->set_userdata('btnhide', 'next');
return 'mx';
}
$query = $p_qry.' LIMIT '.$p_row.','.$curpg.'';
$que= $CI->db->query($query);
}
//RETURN MY DATA AND PUSH
$CI->session->set_userdata('currentpg', $curpg);
return $que->result();
}
//CLEAR PAGINATION SESSION
function clrpagin(){
$CI =& get_instance();
$arr = array(
'currentpg' => '',
'btnhide' => 'prev',
'rowcount' => '',
);
$CI->session->set_userdata($arr);
}
//USE THIS TO CHECK RETURN TYPE AND RESPONSE
function chkreturn(){
//echo "HELO"; exit();
}
}
?>
Please i need this help urgently, can someone help me out, this is running me totally crazy
Thanks