我有不同客户端的下拉列表,每个客户端都有不同的页面,所以当我选择第一个客户端并按下按钮时,选择的客户端页面显示带有分页的数据,我的问题从这里开始然后我选择下一个客户端和按下按钮它会选择客户端页面显示分页数据,当我点击first 1 2 3...last
任何分页按钮时,它会同时执行第一页和第二页的网址,任何人都可以知道修复此问题,谢谢我的代码:
<script type="text/javascript">
$(document).ready(function(){
$("#clientbutton").on("click", function() {
var clientid=$("#client").val();
function loading_show(){
$('#loading').html("<img src='image/loading.png'/>").fadeIn('fast');
}
function loading_hide(){
$('#loading').fadeOut('fast');
}
function loadData(page){
loading_show();
if(clientid == A){
$.ajax({
type: "POST",
url:"clientnetworkpricelist/yourfile.php",
data: "page="+page+"&title="+clientid,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#container").html(msg);
});
}
});
}
else if(clientid == B){
$.ajax({
type: "POST",
url:"clientnetworkpricelist/your1.php",
data: "page="+page+"&title="+clientid,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#container").html(msg);
});
}
});
}
else{
$.ajax
({
type: "POST",
url:"clientnetworkpricelist/yourfile2.php",
data: "page="+page+"&title="+clientid,
success: function(msg)
{
$("#container").ajaxComplete(function(event, request, settings)
{
loading_hide();
$("#container").html(msg);
});
}
});
}
}
loadData(1); // For first time page load default results
$('#container .pagination li.active').live('click',function(){
var page = $(this).attr('p');
loadData(page);
});
$('#go_btn').live('click',function(){
var page = parseInt($('.goto').val());
var no_of_pages = parseInt($('.total').attr('a'));
if(page != 0 && page <= no_of_pages){
loadData(page);
}else{
alert('Enter a PAGE between 1 and '+no_of_pages);
$('.goto').val("").focus();
return false;
}
});
});
});
</script>
PHP
<?php
$client_id = $_POST['title'];
if($client_id!=""){
$page = $_POST['page'];
$cur_page = $page;
$page -= 1;
$per_page = 100;
$previous_btn = true;
$next_btn = true;
$first_btn = true;
$last_btn = true;
$start = $page * $per_page;
$sql_selectsupplier = "select * from supplierprice a JOIN `$client_id` b WHERE b.`net_id` = a.`supp_price_id` ORDER BY `country` ASC LIMIT $start, $per_page";
//print $sql_selectsupplier;
$result1 = mysql_query($sql_selectsupplier);
//print "query". $query;
while($rows=mysql_fetch_array($result1))
{
echo ' <td style="width:69px" class=" '.$rows["net_id"].'">'.$rows["clientid"].'</td>
<td style="width:101px" id="CPH_GridView1_clientid" class=" '.$rows["net_id"].'">'.$rows["region"].'</td>
<td style="width:119px" id="CPH_GridView1_country" class=" '.$rows["net_id"].'">'.$rows["country"].'</td>
'
;
echo '</tr>';
}
/* --------------------------------------------- */
$query_pag_num = "select COUNT( * ) AS count from supplierprice a JOIN `$client_id` b WHERE b.`net_id` = a.`supp_price_id` ORDER BY `country` ASC";
//print $query_pag_num;
$result_pag_num = mysql_query($query_pag_num);
$row = mysql_fetch_array($result_pag_num);
$count = $row['count'];
$no_of_paginations = ceil($count / $per_page);
/* ---------------Calculating the starting and endign values for the loop----------------------------------- */
if ($cur_page >= 7) {
$start_loop = $cur_page - 3;
if ($no_of_paginations > $cur_page + 3)
$end_loop = $cur_page + 3;
else if ($cur_page <= $no_of_paginations && $cur_page > $no_of_paginations - 6) {
$start_loop = $no_of_paginations - 6;
$end_loop = $no_of_paginations;
} else {
$end_loop = $no_of_paginations;
}
} else {
$start_loop = 1;
if ($no_of_paginations > 7)
$end_loop = 7;
else
$end_loop = $no_of_paginations;
}
/* ----------------------------------------------------------------------------------------------------------- */
$msg .= "<div class='pagination'><ul>";
// FOR ENABLING THE FIRST BUTTON
if ($first_btn && $cur_page > 1) {
$msg .= "<li p='1' class='active'>First</li>";
} else if ($first_btn) {
$msg .= "<li p='1' class='inactive'>First</li>";
}
// FOR ENABLING THE PREVIOUS BUTTON
if ($previous_btn && $cur_page > 1) {
$pre = $cur_page - 1;
$msg .= "<li p='$pre' class='active'>Previous</li>";
} else if ($previous_btn) {
$msg .= "<li class='inactive'>Previous</li>";
}
for ($i = $start_loop; $i <= $end_loop; $i++) {
if ($cur_page == $i)
$msg .= "<li p='$i' style='color:#fff;background-color:#006699;' class='active'>{$i}</li>";
else
$msg .= "<li p='$i' class='active'>{$i}</li>";
}
// TO ENABLE THE NEXT BUTTON
if ($next_btn && $cur_page < $no_of_paginations) {
$nex = $cur_page + 1;
$msg .= "<li p='$nex' class='active'>Next</li>";
} else if ($next_btn) {
$msg .= "<li class='inactive'>Next</li>";
}
// TO ENABLE THE END BUTTON
if ($last_btn && $cur_page < $no_of_paginations) {
$msg .= "<li p='$no_of_paginations' class='active'>Last</li>";
} else if ($last_btn) {
$msg .= "<li p='$no_of_paginations' class='inactive'>Last</li>";
}
$goto = "<input type='text' class='goto' size='1' style='margin-top:-1px;margin-left:60px;'/><input type='button' id='go_btn' class='go_button' value='Go'/>";
$total_string = "<span class='total' a='$no_of_paginations'>Page <b>" . $cur_page . "</b> of <b>$no_of_paginations</b></span>";
$msg = $msg . "</ul>" . $goto . $total_string . "</div>"; // Content for pagination
echo $msg;
}
?>