gpt4 book ai didi

php - 使用 codeigniter 在搜索表单中搜索后无法从数据库中获取行数据

转载 作者:行者123 更新时间:2023-11-29 13:59:09 26 4
gpt4 key购买 nike

嘿伙计们,我是 codeigniter 的新手,我正在开发一个应用程序,其中有数据库和数据库中的许多记录。我创建了一个搜索表单,在其中创建了一个文本字段,用户可以在其中填写任何字段值,搜索记录。但这里有一个小问题。当我在文本框中填写名称并单击搜索按钮时, View 上不会显示记录。 。请帮助我 。 。谢谢..

我的 Controller 是:

function search()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('inputsearch', 'Search Your Text Here','required');
if ($this->form_validation->run() == TRUE)
{
$this->load->helper('form');
$this->load->helper('html');
$search_this=$this->input->post('inputsearch');
$this->load->model('mod_user');
$searchmember=$this->mod_user->search_member($search_this);
$data['searchmember'] = $searchmember;
var_dump($searchmember);
$this->load->view('view_home',$data);
$this->load->view('view_homemember',$data);
}
else
{
redirect('ctl_home');
}
}

View 是:

<form class="userinfo" action="" method="post">
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="5%;">&nbsp;</td>
<td width="5%;">&nbsp;</td>
<td width="15%;">Name</td>
<td width="15%;">Moderator Name</td>
<td width="20%;">KCC Branch</td>
<td width="15%;">Father/Husband Name</td>
<td width="15%;">Address</td>
<td width="10%;">Date</td>
</tr>
<?php foreach ($rows as $row):?>
<tr>
<td><?php echo anchor("Ctl_Home/edit_member/" . $row->member_id, 'Edit'); ?></td>
<td><a href="<?php echo site_url("ctl_dbcont/deleteinput/" . $row->member_id);?>" onclick="return confirm('Delete content?');">Delete</a></td>
<td><?php echo $row->member_name; ?></td>
<td><?php echo $row->moderator_name; ?></td>
<td><?php echo $row->branch_name; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->date; ?></td>
</tr>
<?php endforeach; ?>
</table>
</form>

我的模型是:

function search_member($search_this)
{
$query=$this->db->query("SELECT tbl_members.* , tbl_moderators.member_id AS moderator_id, tbl_moderators.member_name AS moderator_name, tbl_moderators.member_no AS moderator_no, tbl_branches.branch_name FROM tbl_members, tbl_members AS tbl_moderators, tbl_branches WHERE tbl_members.moderator_id = tbl_moderators.member_id AND tbl_branches.branch_id = tbl_members.kcc_branch
AND CONCAT(tbl_members.member_name, ' ', tbl_moderators.member_name, ' ',tbl_members.moderator_id, ' ', tbl_moderators.member_id, ' ',tbl_branches.branch_name, ' ',tbl_members.father_name, ' ',tbl_members.address, ' ',tbl_moderators.address, ' ',tbl_members.date, ' ',tbl_moderators.date) like '%".$search_this."%'");
if ($query->num_rows >= 0)
{
foreach($query->result_array() as $row)
{
$data[]=$row;
}
return $data;
}
}

最佳答案

你的循环应该是这样的

<?php foreach ($searchmember as $row):?>
<tr>
<td><?php echo anchor("Ctl_Home/edit_member/" . $row->member_id, 'Edit'); ?></td>
<td><a href="<?php echo site_url("ctl_dbcont/deleteinput/" . $row->member_id);?>" onclick="return confirm('Delete content?');">Delete</a></td>
<td><?php echo $row->member_name; ?></td>
<td><?php echo $row->moderator_name; ?></td>
<td><?php echo $row->branch_name; ?></td>
<td><?php echo $row->father_name; ?></td>
<td><?php echo $row->address; ?></td>
<td><?php echo $row->date; ?></td>
</tr>
<?php endforeach; ?>

它是 $searchmember 作为 $row 而不是 $rows 作为 foreach 中的 $row

关于php - 使用 codeigniter 在搜索表单中搜索后无法从数据库中获取行数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15357673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com