【问题标题】:I want something like facebook status update in Ajax with pagination using codeigniter我想要在 Ajax 中使用 codeigniter 进行分页的 facebook 状态更新
【发布时间】:2014-03-23 08:06:34
【问题描述】:

这是我的控制器“控制”

public function home()
{
$config = array();
$config["base_url"] = base_url().'control/index';
$config["total_rows"] = $this->pagin_db->record_count();
$config["per_page"] = 10;
$config["uri_segment"] = 3;

$this->pagination->initialize($config);

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->pagin_db->
fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();

$this->load->view('header');
$this->load->view('slr');
$this->load->view('index', $data);
$this->load->view('footer');
}

这是我的模型 pagin_db

class Pagin_db extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }

    public function record_count() {
        return $this->db->count_all("searchf");
    }

    public function fetch_location($limit, $start) {
        $this->db->limit($limit, $start);
        $query = $this->db->get("searchf");

        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }

这是我的观点“索引”

<div id="container">
    <center>
<div id="content">
   <div>
  <h1>Countries</h1>
  <div id="body">
    <table>
<?php
foreach($results as $data) {
    echo "<tr><td>".$data->sno."</td><td>".$data->location."</td></tr>";
}
?>
</table>
   <p><?php echo $links; ?></p>
  </div>
 </div>
</div>
</center>
</div>

在这之后,我必须做些什么来添加 ajax 和最后发布的城市,就像 fb 更新一样

别担心这个城市在数据库中最多只有 6 个,所以只有它是可见的

【问题讨论】:

  • 认真的吗?首先做你的工作:列出没有 AJAX 的公司列表,然后询问如何对它们进行分页。仅仅要求一个问题的全部代码就像雇佣一个人而不付钱一样。当你展示你尝试过的东西但它不起作用时,问你的问题是什么,你会得到添加
  • 真的很抱歉 chococroc 我只是一名学生和我的大学项目之一,我不是任何公司的员工 真的很抱歉只是要求代码,因为我不知道从哪里开始代码本身并做没有与 codeigniter 有什么关系,所以只有当你有任何链接可以学习如何在没有 ajax 的情况下创建分页时,请发给我,如果我有任何疑问,我会尝试,我会在这里问
  • XD,好的,别担心,但你做这个问题的方式不符合 SO 的规则。我的建议:首先,创建一个没有 AJAX 和分页的普通页面:sitepoint.com/pagination-with-codeigniter 当你拥有它时,你将能够添加 JS 来制作一个无限滚动,当你点击底部时加载每个页面这页纸。这样做,然后带着特定代码问题回来,;D
  • 谢谢 chocoroc 实施后我会回来的
  • 我已经在上面发布了我的问题,请帮助我

标签: php ajax codeigniter pagination


【解决方案1】:
You must have call ajax when user scroll down. here is example

In View
--------


    <script>
    var track_load = 0;
    var loading  = false;
    $(document).ready(function(){
        $(".container").scroll(function(){
            if($(this).scrollTop() + $(this).innerHeight() >= this.scrollHeight) 
            {
                if(track_load <= total_groups && loading==false)
                {
                    loading = true;
                    var form_data={
                    start:track_load,
                    };
                    $.ajax({
                            url: "display_read",
                            type: "POST",
                            data: form_data,
                            success: function(responseText){
                                $("#your_div_id").append(responseText);
                                track_load++;
                                loading = false;
                            },
                            complete: function(){       
                            }
                      });
                }
            }
        });

    });
    </script>

In Controller
------------
$start=$_POST['start'];

$read=$this->temp_model->fetch_sort_details($start);
for($i=0;$i<count($read);$i++)
{
   //here is your feeds
}

In Model
----------

    function fetch_read($start) {
     $this->db->select("condition");
     $this->db->from("tablename");  
     $this->db->where("condition","apply");
     $this->db->order_by("fieldname","desc");
     $start1= ($start * 4);
     $this->db->limit(4,$start1);
     $query=$this->db->get();
     return $query->result();
    }

May these code helpfull for all other users of stackoverflow... 
thanks

【讨论】:

  • 最初页面只加载不滚动。在这种情况下我们如何获得价值。 jquery代码是什么? @kamlesh
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-09
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 2017-08-17
相关资源
最近更新 更多