Php 分页脚本需要放在codeigniter的查看页面上
CI开发者我的要求是: 我想把分页脚本,这将工作在我的查看页面,即在我的结果页面Php 分页脚本需要放在codeigniter的查看页面上,php,codeigniter,pagination,Php,Codeigniter,Pagination,CI开发者我的要求是: 我想把分页脚本,这将工作在我的查看页面,即在我的结果页面 $per_page=$this->input->post('per_page'); $look = $this->input->post('look'); $age = $this->input->post('age'); $age_from = $this->input->post('age_from'); $age_to = $this->input-&g
$per_page=$this->input->post('per_page');
$look = $this->input->post('look');
$age = $this->input->post('age');
$age_from = $this->input->post('age_from');
$age_to = $this->input->post('age_to');
$se_ct = $this->input->post('sect');
$subsect = $this->input->post('subsect');
$coun_try = $this->input->post('country');
$sta_te = $this->input->post('state');
$ci_ty = $this->input->post('city');
$qualification = $this->input->post('qualification');
$data['showdata']=$this->searchresultss->login($per_page,$look,$age, $age_to,$age_from,$se_ct,$subsect,$coun_try,$sta_te, $ci_ty,$qualification);
$this->load->view('searchresult',$data);
下面是我的型号:
public function login ($per_page=3,$look,$age,$age_to,$age_from,$se_ct,$subsect,$coun_try, $sta_te, $ci_ty,$qualification)
{
$query="SELECT *
FROM users
WHERE
if('$se_ct'!='',sect = '$se_ct' AND if('$subsect' !='',subsect = '$subsect',subsect like '%%'),sect like '%%' AND subsect like '%%')
AND
IF( '$coun_try' !='', country = '$coun_try'
AND
if('$sta_te' !='', state = '$sta_te'
AND
if('$ci_ty' !='',city = '$ci_ty',city like '%%'),state LIKE '%%'
AND city LIKE '%%'), country LIKE '%%'
AND state LIKE '%%'
AND city LIKE '%%' )
AND age >= '$age_from'
AND age <= '$age_to'
AND
IF('$qualification' !='',qualification = '$qualification', qualification LIKE '%%' )
And gender = '$look'
And status='1'";
$data=array();
$query=$this->db->query($query);
$data['results']=$query->result_array();
$data['count']=$query->num_rows();
$data['pages']=ceil($data['count']/3);
return $data;
}
公共功能登录($per_page=3、$look、$age、$age_to、$age_from、$se_ct、$subsect、$conu try、$stau te、$ci_ty、$qualification)
{
$query=“选择*
来自用户
哪里
if(“$se_-ct”!=”,sect=“$se_-ct”和if(“$subsect”!=”,subsect=“$subsect”,类似于“%”的子集),类似于“%”的sect和类似于“%”的子集)
及
如果(“$counu-try”!=”,国家=“$counu-try”
及
如果('$sta_UTE'!='',状态='$sta_UTE'
及
如果(“$ci_ty”!=”,城市=“$ci_ty”,类似城市“%”),状态类似“%”
城市像“%”,乡村像“%”
和类似“%”的状态
以及类似“%”的城市)
年龄>=“$age\u from”
和年龄控制者
public function users($offset = 0)
{
$this->load->library('session');
if ($postdata = $this->session->flashdata('post_data')) {
foreach (unserialize($postdata) as $key => $value) {
$_POST[$key] = $value;
}
}
$this->session->set_flashdata('post_data', serialize($this->input->post()));
$data = array();
$limit = $this->input->post('per_page');
$look = $this->input->post('look');
$age = $this->input->post('age');
$age_from = $this->input->post('age_from');
$age_to = $this->input->post('age_to');
$se_ct = $this->input->post('sect');
$subsect = $this->input->post('subsect');
$coun_try = $this->input->post('country');
$sta_te = $this->input->post('state');
$ci_ty = $this->input->post('city');
$qualification = $this->input->post('qualification');
$results = $this->searchresultss->login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification);
//for base_url()
$this->load->helper('url');
//Pagination Config
$config = array();
$config['base_url'] = base_url("searchresults/users/");
$config['total_rows'] = count($results);
$config['per_page'] = $limit;
$this->load->library('pagination', $config);
$data['pagination_links'] = $this->pagination->create_links();
//Reducing the number of results for the view
/** NOTE: This is not the most efficient way **/
$data['results'] = array_slice($results, $offset, $limit);
$this->load->view('searchresult', $data);
}
我理解这只是一个问题,您可能没有将所有代码都放在这里,但如果您放在这里,您确实需要考虑使用表单验证,因为此代码可能非常容易受到攻击
型号
public function login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification)
{
return $this->db->query("SELECT *
FROM users
WHERE
if('$se_ct'!='', sect = '$se_ct' AND if('$subsect' !='',subsect = '$subsect',subsect like '%%'),sect like '%%' AND subsect like '%%')
AND
IF( '$coun_try' !='', country = '$coun_try'
AND
if('$sta_te' !='', state = '$sta_te'
AND
if('$ci_ty' !='',city = '$ci_ty',city like '%%'),state LIKE '%%'
AND city LIKE '%%'), country LIKE '%%'
AND state LIKE '%%'
AND city LIKE '%%' )
AND age >= '$age_from'
AND age <= '$age_to'
AND
IF('$qualification' !='',qualification = '$qualification', qualification LIKE '%%' )
And gender = '$look'
And status='1'")->result();
}
;
//测试端
foreach($results作为$result){
echo$result->email.“
”;
}
}
希望这有帮助!您不应该期望我们给您带来任何东西。我们在这里是为了向您展示正确的方向,而不是提高您的期望值。请删除文本中的代码格式。只有代码应该是
代码格式
。您应该学会更好地设置问题的格式。如果您希望有人为您付出努力,请你应该先给自己写一些你说的是对的,我试了三天,但我失败了,所以我把我的问题简单地发了出来。我编辑了你说的MachineAdict先生。Vicky,还有一些格式为代码的普通问题文本。请花几分钟时间更正。保存时,查看问题的格式是否正确。你认为呢您是否将其他内容传递到控制器方法?控制器方法的名称是什么?此页面的url是什么?如果我完全复制控制器,我将获得emty数组,但未获得任何输出…到目前为止,您已经为我花费了很多时间..因此请求您再花费一些时间您是否已将该方法的名称更改为用户在这种情况下,我不知道为什么不起作用。谷歌如何打开错误日志并查看问题所在。$config[“uri_段”]=3;$page=($this->uri->segment(2))?$this->uri->segment(3):0;我们忘记使用这个了吗//
public function login($look, $age, $age_to, $age_from, $se_ct, $subsect, $coun_try, $sta_te, $ci_ty, $qualification)
{
return $this->db->query("SELECT *
FROM users
WHERE
if('$se_ct'!='', sect = '$se_ct' AND if('$subsect' !='',subsect = '$subsect',subsect like '%%'),sect like '%%' AND subsect like '%%')
AND
IF( '$coun_try' !='', country = '$coun_try'
AND
if('$sta_te' !='', state = '$sta_te'
AND
if('$ci_ty' !='',city = '$ci_ty',city like '%%'),state LIKE '%%'
AND city LIKE '%%'), country LIKE '%%'
AND state LIKE '%%'
AND city LIKE '%%' )
AND age >= '$age_from'
AND age <= '$age_to'
AND
IF('$qualification' !='',qualification = '$qualification', qualification LIKE '%%' )
And gender = '$look'
And status='1'")->result();
}
<?php
echo $pagination_links;
if (empty($results)) {
echo 'Results set is empty';
} else {
/**
* The code between the "testing comment can be removed, however, use it to check that you are typing the parameter names corrent (remember it is case-sensitive)"
* Remove the code between the "Testing" comments when you're happy.
*/
//Testing
echo '<pre>';
echo var_dump($results);
echo '</pre><br /><br />';
//Testing End
foreach ($results as $result) {
echo $result->email.'<br />';
}
}