dovs36921 2015-12-28 14:03
浏览 26
已采纳

too long

I have fetched the record in my model against each user from database as follows:

public function counter_records() {

$table = 'usersearchs';
$this->db->select("domain, time");

$this->db->from($table);
$this->db->where("user_id", $this->session->userdata("user_id"));
$res = $this->db->get();
$num_of_records = $res->num_rows();

return $num_of_records;
}

Now I want to show these number of records into a view file for each user account, they have to know how many records they have.

  • 写回答

1条回答 默认 最新

  • doujing3896 2015-12-28 14:22
    关注

    Use this function for display all records against user_id in your Model:

    public function userData()
    {
        $results = array();
        $table = 'usersearchs';
        $this->db->select("domain, time");
        $this->db->from($table);
        $this->db->where("user_id",$this->session->userdata("user_id"));
        $query = $this->db->get();
        $num_of_records = $query->num_rows();
        if($num_of_records > 0){
            $results = $query->result_array();
        }   
        return $results;    
    }
    

    In Controller: call this function in your controller file like.

    $this->load->model('model_yourmodel');
    $data['records'] = $this->model_yourmodel->userData();
    

    And pass this data in your view from controller as like:

    $this->load_view("yourviewpath" , $data);
    

    In HTML View File: Use loop for display this data like that:

    <?
    $total_records = count($records);
    if($total_records <= 3){
    echo (4-$total_records). " records remaining in your account";
    }
    else{
    echo "You have reached the maximum record";
    }
    
    if($total_records > 0){  // $records that you have pass from your controller.
       foreach($records as $value){
       ?>
       // Your HTML Code 
       Domain <?=$value['domain']?> - Time <?=$value['time']?> <br/>
       // Your HTML Code
       <?
       }
    }
    else{
       // your HTML
       echo "No record found";
       // your HTML
    }
    ?>
    

    Result should be like that in HTML:

    domain1 - time1 
    domain2 - time2 
    domain3 - time3 
    domain4 - time4 
    domain5 - time5 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP