我有一个网站,我需要按性别添加搜索选项。
如果用户点击男性性别选项,则必须显示数据库及其相关信息中的所有男性。
同样适用于女性性别选择。
我有代码,但它无法正常工作。
这是代码
我做模特时
$this->db->where('gender');
它给了我输出但是当我使用
时$this->db->where('gender'='male');
它显示了我的空白页
控制器
function searchmale()
{
if($this->session->userdata('is_logged_in') == true)
{
$this->load->view('searchmalegender');
}
else
$this->index();
}
function searchmaleconfirm()
{
if($this->session->userdata('is_logged_in') == true)
{
$data['freemembers'] = $this->freemember_model->searchmale();
// $data['domesticmembers'] = $this->domesticmember_model->searchmale();
//$data['overseasmembers'] = $this->overseasmember_model->search($search);
//$data['messages'] = $this->messageboard_model->getallmessages();
$sessiondata = array();
$sessiondata = $this->session->all_userdata();
$this->load->view('maleresult',$data);
}
else
$this->index();
Model.php
function searchmale(){
$this->db->from('free_members');
$this->db->where('gender'= 'male');
//$this->db->order_by("id", "asc");
//if ($rows > 0) {
// $this->db->limit($rows, $limit_from);
//}
$query = $this->db->get();
$query_result = $query->result();
return $query_result;
}
查看searchmalegender.php
<?php echo form_open_multipart("admin/searchmaleconfirm");?>
<div class="form-group">
<span id="provincedropdown"></span>
</div><!-- /.form-group -->
<div class="form-group">
<button type="submit">Search</button>
</div>
</form>
查看maleresult.php
<?php $sessiondata = $this->session->all_userdata();?>
<div class="box">
<div class="box-header">
<h3 class="box-title">Free Members</h3>
</div><!-- /.box-header -->
<div class="box-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th><center>Sr#</th>
<th><center>Full Name</th>
<th><center>Mobile Number</th>
<th><center>Membership# / CNIC</th>
<th><center>Email Address</th>
<th><center>Date of Birth</th>
<th><center>Province</th>
<th><center>District</th>
<th><center>Tehsil</th>
<th><center>Union Council</th>
<th><center>Silsalah</th>
<th><center>Block</th>
<th><center>Ward</th>
<th><center>Polling Station</th>
<th><center>Registered</th>
</tr>
</thead>
<tbody>
<?php $sr=0;?>
<?php foreach ($freemembers as $member): ?>
<tr><td><center><?php echo $sr+=1; ?></td><td><center><?php echo $member->first_name; ?></td>
<td><center><?php echo $member->mobile; ?></td><td><center><?php echo $member->cnic; ?></td>
<td><center><?php echo $member->email; ?></td><td><center><?php echo $member->dob; ?></td>
<td><center><?php echo $member->province; ?></td><td><center><?php echo $member->district; ?></td><td><center><?php echo $member->tehsil; ?></td><td><center><?php echo $member->uc; ?></td>
<td><center><?php echo $member->silsalano; ?></td><td><center><?php echo $member->blockcode; ?></td>
<td><center><?php echo $member->wardno; ?></td><td><center><?php echo $member->pollingstation; ?></td><td><center><?php echo $member->created; ?></td>
<?php /*?><?php if($sessiondata['data_modification']):?><?php */?>
<?php if($sessiondata['username'] != 'bilal.sabir'):?>
<td><center><a href="<?php echo base_url() . "index.php/admin/deletefreemember/" . $member->id; ?>">delete</a></td>
<?php endif;?>
<?php /*?> <?php if($sessiondata['data_modification'] || $sessiondata['username'] == 'irfan' || $sessiondata['username'] == 'kashif'):?><?php */?>
<?php if($sessiondata['username'] != 'bilal.sabir'):?>
<td><center><a href="<?php echo base_url() . "index.php/admin/printcardfree/" . $member->id; ?>">print</a></td>
<td><center><a href="<?php echo base_url() . "index.php/admin/editprofilefree/" . $member->id; ?>">edit</a></td>
<td><center><a href="<?php echo base_url() . "index.php/admin/changepasswordfree/" . $member->id; ?>">change pwd</a></td>
<?php endif;?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div><!-- /.col -->
</div><!-- /.row -->
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
答案 0 :(得分:0)
你应该解决这个问题:
$this->db->where('gender','male');
答案 1 :(得分:0)
希望这有助于:)
试试这段代码:
$this->db->where('gender', 'male');
或
$this->db->where('gender =', 'male');
您可以参考此文档https://www.codeigniter.com/userguide3/database/query_builder.html
-KD
答案 2 :(得分:0)
在Model.php
中,将WHERE
子句更改为以下任何一项:
$this->db->where('gender = male');
OR
$this->db->where('gender = ', 'male');
OR
$this->db->where('gender', 'male');
OR
$this->db->where(array('gender', 'male') );