[eluser]pipiet06[/eluser]
Hi all..
i wanna getData for my search in js.
but,, every I did search there is a bug "
<b>Fatal error</b>: Call to a member function num_rows() on a non-object in <b>C:\wamp\www\hid\hidsystem\application\models\ed\MSummary.php</b> on line <b>47</b>"
this is my controller
Code:
function get_data()
{
$start = ($this->input->post('start'))? $this->input->post('start'):0;
$limit = ($this->input->post('limit'))? $this->input->post('limit'):10;
$query = $this->input->post('query');
$fields = $this->input->post('fields');
$startDate = $this->input->post('startDate');
$endDate = $this->input->post('endDate');
$idsite = $this->input->post('idsite');
$idfleet = $this->input->post('idfleet');
$idprefix = $this->input->post('idprefix');
$eqplan = $this->input->post('eqplan');
$category = $this->input->post('category');
$type = $this->input->post('type');
$idcomponent = $this->input->post('idcomponent');
$description = $this->input->post('description');
$query = $this->MSummary->getData($start,$limit,$query,$fields,$startDate,$endDate,$idsite,$idfleet,$idprefix,$eqplan,$category,$type,$idcomponent,$description);
$total = $query['num_rows'] ;
$rowData = array("total"=>$total);
if ($total > 0 )
{
foreach($query['result'] as $row)
{
$rowData['rows'][] = array(
'idvims_summary'=>$row['idvims_summary']
,'startDate'=>$row['event_date']
,'idsite'=>$row['idsite']
,'idfleet'=>$row['idfleet']
,'idprefix'=>$row['idprefix']
,'eqplan'=>$row['eqplan']
,'category'=>$row['category']
,'type'=>$row['type']
,'idcomponent'=>$row['idcomponent']
,'id_event'=>$row['id_event']
,'description'=>$row['description']
,'rating'=>$row['rating']
);
}
}
else{
$rowData['rows'] = "";
}
echo json_encode($rowData);
}
this is my models
Code:
function getData($start,$limit,$query,$fields,$startDate,$endDate,$idsite,$idfleet,$idprefix,$eqplan,$category,$type,$idcomponent,$description)
{
if ($query)
{
/**
* Field Parsing
*/
$fields = str_replace("[","",$fields);
$fields = str_replace("]","",$fields);
$fields = str_replace("\"","",$fields);
$fields = explode(",",$fields);
$search = array();
foreach ($fields as $fd)
{
$search[$fd] = $query;
}
// $data['num_rows'] = $this->db->count_all_results('tblvims_summary');
[color=red]$sql = $this->db->query("SELECT
a.*
, b.description
FROM
tblvims_summary a
LEFT JOIN
tblid_event AS b ON b.id = a.id_event
OR_LIKE
$search
LIMIT
$start,$limit"
);
$queryn = $this->db->query($sql);
if ($queryn->num_rows() > 0) {
$data['num_rows'] = $queryn->num_rows();
$query = $this->db->query($sql . "LIMIT $start,$limit");
$data['result'] = $query->result_array();
$this->output->enable_profiler(true);
exit;
}
// $data['result'] = $query->result_array();
return ($query->num_rows() > 0) ? $data : FALSE;
}[/color]
else
{
$sql = "SELECT
a.*
, b.description
FROM
tblvims_summary a
LEFT JOIN
tblid_event AS b ON b.id = a.id_event
where
DATE(event_date) >= STR_TO_DATE('$startDate', '%d-%m-%Y') AND DATE(event_date) <= STR_TO_DATE('$endDate', '%d-%m-%Y')
AND idsite='$idsite'
AND idfleet='$idfleet'
AND idprefix='$idprefix'
AND eqplan='$eqplan'
AND category='$category'
AND a.type='$type'
AND a.idcomponent='$idcomponent'";
$queryn = $this->db->query($sql);
if ($queryn->num_rows() > 0) {
$data['num_rows'] = $queryn->num_rows();
$query = $this->db->query($sql . "LIMIT $start,$limit");
$data['result'] = $query->result_array();
}
return ($query->num_rows() > 0) ? $data : FALSE;
}
what i'm missing or my code is wrong?
thanks