我制作了一个表格列表,其中显示了由多个记录组成的表格。它目前每次最多显示10个。我有一个按钮,点击后会显示表格中的下10条记录。我想知道如何编写它以使其工作?
function showAll(qstring,qtype){
$("#vsdiv").show();
var myurl="scripts/searchadmin.php";
$.ajax({
url: myurl, dataType:'json',data:{querystring:qstring,querytype:qtype},
success: function(member){
$("#resultstable").append('<tr class="yellow">'+
'<th>#REC</th><th>JOINED</th><th>USER NAME</th>'+
'<th>CONTACT</th><th>ADDRESS</th><th>PHONE</th>'+
'<th>EMAIL</th><th>STATUS</th><th>SELECT</th></tr>');
var j=0;var totrecs=1;
for(var i=0;i<10;i++){
$("#resultstable").append('<tr class="trow'+j+'">'+
'<td class="ids" id="z'+i+'">'+totrecs+'</td>'+
'<td>'+member[i].jdate+'</td>'+
'<td class="users" id="username'+i+'">'+member[i].username+'</td>'+
'<td id="contact'+i+'">'+member[i].fname+' '+member[i].lname+'</td>'+
'<td id="myaddress'+i+'">'+member[i].address1+' '+member[i].town+'</td>'+
'<td id="phone'+i+'">'+member[i].phone+'</td>'+
'<td id="email'+i+'">'+member[i].email+'</td>'+
'<td id="status'+i+'">'+member[i].status+'</td>'+
'<td><input type="checkbox" name="whome" id="showMe'+i+'"'+
'class="boxes" onclick="getMe('+i+')" /></td></tr>');
$('#sr').html('Showing 1 of '+member.length+' Members')
});
totrecs++;
j++;
}
}
});
}
这是显示前10条记录的当前功能,当我点击按钮时,如何显示下一组10?有什么想法吗?
答案 0 :(得分:0)
您可以实现此目的的一种方法是向查询添加范围信息,这可能看起来像这样:
var rangestart = 0;
var rangeend = 9;
var rangeincrement = 10;
function showAll(qstring,qtype){
$("#vsdiv").show();
var myurl="scripts/searchadmin.php";
$.ajax({
url: myurl, dataType:'json',data:{querystring:qstring,querytype:qtype,rangestart:rangestart,rangeend:rangeend},
success: function(member){
$("#resultstable").append('<tr class="yellow">'+
'<th>#REC</th><th>JOINED</th><th>USER NAME</th>'+
'<th>CONTACT</th><th>ADDRESS</th><th>PHONE</th>'+
'<th>EMAIL</th><th>STATUS</th><th>SELECT</th></tr>');
var j=0;var totrecs=1;
for(var i=0;i<10;i++){
$("#resultstable").append('<tr class="trow'+j+'">'+
'<td class="ids" id="z'+i+'">'+totrecs+'</td>'+
'<td>'+member[i].jdate+'</td>'+
'<td class="users" id="username'+i+'">'+member[i].username+'</td>'+
'<td id="contact'+i+'">'+member[i].fname+' '+member[i].lname+'</td>'+
'<td id="myaddress'+i+'">'+member[i].address1+' '+member[i].town+'</td>'+
'<td id="phone'+i+'">'+member[i].phone+'</td>'+
'<td id="email'+i+'">'+member[i].email+'</td>'+
'<td id="status'+i+'">'+member[i].status+'</td>'+
'<td><input type="checkbox" name="whome" id="showMe'+i+'"'+
'class="boxes" onclick="getMe('+i+')" /></td></tr>');
$('#sr').html('Showing 1 of '+member.length+' Members')
});
totrecs++;
j++;
}
rangestart += rangeincrement; // this assigns the new range start value
rangeend += rangeincrement; // assign new range end value
}
});
}
然后您的按钮再次执行相同的查询。您还需要在服务器端更改查询,只返回您需要的范围,例如
SELECT * FROM xyz WHERE xyz.somevalue = querystring LIMIT rangestart, rangeend;
那应该得到你想要的结果。