类型:错误消息:调用字符串上的成员函数 result() 文件名:CI\application\models\Country_model.php 行号:34
Type: Error Message: Call to a member function result() on string Filename: CI\application\models\Country_model.php Line Number: 34
请帮忙。我卡住了。无法让搜索按钮工作(过滤器)
jTable Codeigniter 3。干杯。
Type: Error Message: Call to a member function result() on string Filename: CI\application\models\Country_model.php Line Number: 34
这是我的 model.php
public function get_country() {
if(empty($this->input->post('country_name'))){
$country_name=NULL;
$result = $this->db->query("SELECT country_id, country_code, country_name, surface_area,
continent_name, continent, population, capital_city, record_date
FROM country
WHERE deleted = 0
ORDER BY " . filter_input(INPUT_GET, "jtSorting") . "
LIMIT " . filter_input(INPUT_GET, "jtStartIndex") . "," . filter_input(INPUT_GET, "jtPageSize") . ";");
$this->db->where('deleted','0');
} else {
$country_name = filter_input(INPUT_POST, 'country_name');
$result = ("SELECT country_id, country_code, country_name, surface_area,
continent_name, continent, population, capital_city, record_date
FROM country
WHERE deleted = 0 AND
country_name LIKE '%".$country_name."%'"
. "ORDER BY " . filter_input(INPUT_GET, "jtSorting") . "
LIMIT " . filter_input(INPUT_GET, "jtStartIndex") . "," . filter_input(INPUT_GET, "jtPageSize") . ";");
}
$rows = array();
foreach ($result->result() as $row) {
$rows[] = $row;
}
return $rows;
}
这是我的 controller.php
public function get_country() {
$this->load->model('Country_model');
$rows = $this->Country_model->get_country();
$result = $this->db->get("country");
$recordCount = $result->num_rows();
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
和我的view.php
<div class="filtering">
<form>
Country Name: <input type="text" name="country_name" id="country_name" />
country_name: {
title: 'Country Name',
width: '17%'
},
country_code: {
title: 'Country Code',
width: '11%'
},
surface_area: {
title: 'Surface Area',
width: '13%'
},
continent_name: {
title: 'Continent Name',
width: '13%'
},
continent: {
title: 'Continent Code',
width: '11%'
},
population: {
title: 'Population',
width: '13%'
},
capital_city: {
title: 'Capital City',
width: '11%'
},
record_date: {
title: 'Record Date',
width: '11%',
type: 'date',
displayFormat: 'dd.mm.yy',
create: false,
edit: false,
sorting: false
}
},
$('#LoadRecordsButton').click(function (e) {
e.preventDefault();
$('#countryTable').jtable('load', {
country_name: $('#country_name').val(),
});
});
$('#LoadRecordsButton').click();
});
</script>
else部分你做错了
$result = ("SELEC...
它必须像
$result = $this->db->query("SELEC...
希望能解决你的问题...
请帮忙。我卡住了。无法让搜索按钮工作(过滤器) jTable Codeigniter 3。干杯。
Type: Error Message: Call to a member function result() on string Filename: CI\application\models\Country_model.php Line Number: 34
这是我的 model.php
public function get_country() {
if(empty($this->input->post('country_name'))){
$country_name=NULL;
$result = $this->db->query("SELECT country_id, country_code, country_name, surface_area,
continent_name, continent, population, capital_city, record_date
FROM country
WHERE deleted = 0
ORDER BY " . filter_input(INPUT_GET, "jtSorting") . "
LIMIT " . filter_input(INPUT_GET, "jtStartIndex") . "," . filter_input(INPUT_GET, "jtPageSize") . ";");
$this->db->where('deleted','0');
} else {
$country_name = filter_input(INPUT_POST, 'country_name');
$result = ("SELECT country_id, country_code, country_name, surface_area,
continent_name, continent, population, capital_city, record_date
FROM country
WHERE deleted = 0 AND
country_name LIKE '%".$country_name."%'"
. "ORDER BY " . filter_input(INPUT_GET, "jtSorting") . "
LIMIT " . filter_input(INPUT_GET, "jtStartIndex") . "," . filter_input(INPUT_GET, "jtPageSize") . ";");
}
$rows = array();
foreach ($result->result() as $row) {
$rows[] = $row;
}
return $rows;
}
这是我的 controller.php
public function get_country() {
$this->load->model('Country_model');
$rows = $this->Country_model->get_country();
$result = $this->db->get("country");
$recordCount = $result->num_rows();
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
和我的view.php
<div class="filtering">
<form>
Country Name: <input type="text" name="country_name" id="country_name" />
country_name: {
title: 'Country Name',
width: '17%'
},
country_code: {
title: 'Country Code',
width: '11%'
},
surface_area: {
title: 'Surface Area',
width: '13%'
},
continent_name: {
title: 'Continent Name',
width: '13%'
},
continent: {
title: 'Continent Code',
width: '11%'
},
population: {
title: 'Population',
width: '13%'
},
capital_city: {
title: 'Capital City',
width: '11%'
},
record_date: {
title: 'Record Date',
width: '11%',
type: 'date',
displayFormat: 'dd.mm.yy',
create: false,
edit: false,
sorting: false
}
},
$('#LoadRecordsButton').click(function (e) {
e.preventDefault();
$('#countryTable').jtable('load', {
country_name: $('#country_name').val(),
});
});
$('#LoadRecordsButton').click();
});
</script>
else部分你做错了
$result = ("SELEC...
它必须像
$result = $this->db->query("SELEC...
希望能解决你的问题...