下一个未成年人的ID,这是js脚本调用AJAX如何选择MySQL的
var tempScrollTop, currentScrollTop = 0;
$(document).scroll(function(){
currentScrollTop = $(document).scrollTop();
var ids = new Array();
if (tempScrollTop < currentScrollTop)
{
var result = currentScrollTop % 100;
if(result == 0 || (result > 20 && result < 30))
{
var items = $(".item");
var items_l = items.length;
for(var i = 0; i < items_l; i++)
{
ids[i] = parseInt(items[i].id.replace(/\D+/g,""));
}
ids = ids.sort();
var last_id = ids[0];
$.ajax({
url: "ajax/load",
type: "POST",
data: {last_id : last_id},
success: function(res){
$("#content").append(res);
}
});
}
}
,这是控制器方法
public function ajaxLoad()
{
$last_id = intval($this->input->post("last_id"));
//$last_id++;
$db_data['query'] = $this->db->query("SELECT * FROM items WHERE id < ".$last_id." LIMIT 1");
$data['content'] = $this->load->view('item', $db_data, true);
echo $data['content'];
}
这样的目的是,我想要得到的在mysql中的id是次要的,即页面当前的次要id,例如,如果页面中的次要id是25,我想选择下一个N记录,但是如果我写入全部来自其中id为< current_id的项目数据库每次选择第一行,因为它是所有数据库中最小的,但我需要NEXT未成年人,如何做到这一点?
我的意思是20比25的下一个未成年人,但我不希望选择15,我得到20
之前让假设我们有这样的ID在DB:14,26,30,40 ..
因此,页面中的未成年人是30,我想选择下一个小ID,它将是26,然后14,这可能做到这一点吗?
哇,谢谢我甚至没有想过,是的,它的工作:)))) – 2012-02-21 19:10:12
@yeahitsme很高兴听到它。如果它解决了您的问题,请不要忘记接受这个答案。 – 2012-02-21 19:10:55
我需要15的声誉投票,抱歉:(( – 2012-02-21 19:23:54