【问题标题】:Codeigniter Search User and detailsCodeigniter 搜索用户和详细信息
【发布时间】:2020-02-20 13:32:46
【问题描述】:

数据库表:tblcg

id | firstName | lastName | zipcode | City

当用户在搜索表单中输入 zipcode(like-42872) 并点击搜索按钮然后显示如下......

----------------------------------------------
|     Name      |   Zipcode   |     City     | 
----------------------------------------------
|  Devid Johne  |    42872    |  Northbrook  |
----------------------------------------------
|  Betty Flore  |    42872    |  Northbrook  |
----------------------------------------------
|  Abard Gree   |    42872    |  Northbrook  |
----------------------------------------------

注意:结果显示应该在同一页面上。

请帮我做这件事。我知道你可以做到这一点。请先生这样做

【问题讨论】:

  • 您可以在同一页面上使用 ajax 获取结果
  • 我不需要其他结果。我需要我要搜索的结果。
  • 如果可以,请输入代码
  • 你有没有写过代码。我可以更正你的代码
  • 你的代码在哪里?除非您将其编辑为更具体的内容,包括您尝试过的代码,否则您的问题可能会被关闭。 SO 不是代码编写服务。查看how to ask,以及如何创建minimal, complete, and verifiable example

标签: database codeigniter search


【解决方案1】:

这是你可以做到的。

查看:

<form action="<?php echo site_url('search/search_keyword');?>" method = "post">
<input type="text" name = "keyword" />
<input type="submit" value = "Search" />
</form>

控制器:

Class Search Extends CI_Contrller
{
    function __construct()
    {
        parent::__construct();
        $this->load->model('mymodel');
    }

    function search_keyword()
    {
        $keyword    =   $this->input->post('keyword');
        $data['results']    =   $this->mymodel->search($keyword);
        $this->load->view('result_view',$data);
    }

}

型号:

Class Mymodel Extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function search($keyword)
    {
        $this->db->like('zipcode ',$keyword);
        $query  =   $this->db->get('tblcg');
        return $query->result();
    }
} 

编辑:

这是显示数据的视图。 result_view.php

<table>
<?php foreach($results as $row){ ?>
    <tr>
        <td><?php echo $row->name?></td>
        <td><?php echo $row->zipcode ?></td>
        <td><?php echo $row->City?></td>
    </tr>
<?php } ?>
</table>

【讨论】:

猜你喜欢
  • 2018-07-06
  • 2020-04-24
  • 2018-03-01
  • 1970-01-01
  • 2015-05-31
  • 1970-01-01
  • 1970-01-01
  • 2015-05-20
  • 2016-05-01
相关资源
最近更新 更多