分页 - 不工作

时间:2011-11-24 23:55:28

标签: php javascript mysql pagination

我不明白为什么我的分页不起作用!它默认显示ok,但是当点击'Next'页面或某些页码时没有任何反应,根本没有改变页面。这就像没有识别pagination.js或pagination_class.php。 我有另一部分网站工作正常,所以不确定我错过了一些明显的东西吗? 在同一文件夹中有4个与此相关的文件:myaccount_betinghistory.php, myaccount_bettinghistory_sub.php, pagination.js, pagination_class.php.

以下是所有要查看的文件的所有代码,我希望你能在那里找到bug!

myaccount_bettinghistory.php:

<?php

error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');

?>

<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />


<?PHP

//Session start
@session_start();

//Path to root
$root = realpath($_SERVER["DOCUMENT_ROOT"]);

//Require Init
$mode = array();
$mode[] = 'nohtml';
require_once $root . "/inc/php/init.php";

{

?>

<?PHP

}

?>

<?
$qry = "
SELECT timelive,bidprice,match_title,selection,winnings_with_startamount,odds,odds*10 AS gainedodds,username,
CASE 
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status LIKE 'E' THEN 'pending'
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status NOT LIKE 'E' THEN 'active'
WHEN each_bid_recorded_Part2.result liKE each_bid_recorded_Part2.selection THEN 'WON'
WHEN each_bid_recorded_Part2.result NOT liKE each_bid_recorded_Part2.selection THEN 'LOST'
END AS result
FROM each_bid_recorded_Part2 WHERE each_bid_recorded_Part2.username LIKE '" . $_SESSION['username'] . "'

";

$qry .= " ORDER BY timelive DESC";


//for pagination
$starting=0;
$recpage = 4;//number of records per page

$obj = new pagination_class($qry,$starting,$recpage);       
$result = $obj->result;



function getStyleColorForStatus($status) {
  if ($status == 'WON') {
return '#99ff99';
  }
  else if ($status == 'LOST') {
return '#ff9999';
  }
  else if ($status == 'pending') {
return '#e5e5e5';
  }
  else if ($status == 'active') {
return '#ffffcc';
  }
  return '';
}



?>


<div>
  <div class="pageTop"><img src="images/icons/faqicon.png" width="37" height="37" align=absbottom>      Betting History</div>
    <tr>
    <td>&nbsp;</td>
    </tr>
</div>
  <div>
<p style="font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #535252; text-align: left;">Check your bets with you as a last bidder.</p>
</div>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-size:11px; color: #535252;">
        <form name="form1" action="myaccount_bettinghistory.php" method="POST" style="background-color:#f9f9f9; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1);">

        <table border="0" align="left" width="500px" padding-left="0px" style="background:#F9F9F9;">



        <tr><TD colspan="0">

        <div id="page_contents">

            <table width="755px" cellspacing="0" cellpadding="5" align="center" frame="box" rules="none" style="padding-bottom:2px; margin-bottom:0px; margin-top:3px; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1); border: 1px solid #cccccc;">
            <tr style="height: 40px;">
<td width="30%" align="center" td class="winheader"><div class="glowtext">Event Start Time</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Bid Cost</div></td></td>  
<td width="35%" align="center" td class="winheader"><div class="glowtext">Market/Event</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Selection</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winnings</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Odds</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Gained Odds</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winning Bidder</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Final Result</div></td></td>
            </tr>
            <?if(mysql_num_rows($result)!=0){
                $counter = $starting + 1;
                while($data = mysql_fetch_array($result)) {?>



    <tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">



                    <td align="center"><font color="#333"><? echo $data['timelive']; ?></TD>
                    <td align="center">&euro; <? echo $data['bidprice']; ?></TD>        
                    <td align="left"><font color="#0070c0"><? echo $data['match_title']; ?></TD>                
                    <td align="left"><? echo $data['selection']; ?></TD>
                    <td align="center"><font color="green">&euro; <? echo $data['winnings_with_startamount']; ?></TD>
                    <td align="center"><? echo $data['odds']; ?></TD>
                    <td align="center"><? echo $data['gainedodds']; ?></TD>
                    <td align="center"><? echo $data['username']; ?></TD>
                    <td align="center" style="background-color:<?php echo getStyleColorForStatus($data['result']); ?>"><? echo $data['result']; ?></td>
                    </tr>


                <?
                    $counter ++;
                } ?>


                <tr><TD align="center" colspan="10" style="padding-bottom:1px; padding-top:10px; color:#333;"><? echo $obj->anchors; ?></TD></tr>
                <tr><TD align="center" colspan="10" style="padding-bottom:10px; padding-top:5px; color:#333;"><? echo $obj->total; ?></TD></tr>
            <?}else{?>
                <tr><TD align="center" colspan="10" style="padding-bottom:10px padding-top:10px; color:red;">No Data Found</TD></tr>
            <?}?>
            </TD></tr>
            </table>
        </div>
        </tr>
        </TD>
    </form>
</table>

<STYLE>

*{ margin-bottom:0; }



#pagination-flickr li{
margin:0px;
padding:0px;
float:left;
font-size:10px;
}
#pagination-flickr a{
float:left;
padding:5px 7px;
margin-right:5px;
border:solid 1px #4d7dc5;
text-decoration:none;
background:#FFFFFF;
color:#4d7dc5;
font-size:10px;
}
#pagination-flickr .previous-off,
#pagination-flickr .next-off {
border:solid 1px #DDDDDD;
cursor:default;
background:#FFFFFF;
border:solid 1px #BBBBBB;
color:#BBBBBB;
padding:4px 6px;
margin-right:5px;
font-size:10px;
}
#pagination-flickr .next a,
#pagination-flickr .previous a {
background:#FFFFFF;
border:solid 1px #BBBBBB;
color:#BBBBBB;
font-size:10px;
}
#pagination-flickr .active{
cursor:default;
background:#4d7dc5;
color:#FFFFFF;
padding:4px 6px;
margin-right:5px;
border:solid 1px #4d7dc5;
font-size:10px;
}
#pagination-flickr a:link,
#pagination-flickr a:visited {
padding:4px 6px;
margin-right:5px;
border:solid 1px #4d7dc5;
background:#FFFFFF;
color:#4d7dc5;
font-size:10px;
}
#pagination-flickr a:hover{
padding:4px 6px;
margin-right:5px;
border:solid 1px #4d7dc5;
background:#ffc04a;
color:#000;
font-size:10px;
}


body,table
{

font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
padding-bottom:5px;
empty-cells: show;


}

.glowtext
{
text-shadow: 0 0 20px white;
color:#333;
font-weight:bold;
}


</STYLE> 

myaccount_bettinghistory_sub.php:

<?php
error_reporting(E_ALL^E_NOTICE);
include('pagination_class.php');

?>

<script language="JavaScript" src="pagination.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />

<?PHP

//Session start
@session_start();

//Path to root
$root = realpath($_SERVER["DOCUMENT_ROOT"]);

//Require Init
$mode = array();
$mode[] = 'nohtml';
require_once $root . "/inc/php/init.php";


{
?>

<?PHP
}

?>


<?
$qry = "
SELECT timelive,bidprice,match_title,selection,winnings_with_startamount,odds,odds*10 AS gainedodds,username,
CASE 
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status LIKE 'E' THEN 'pending'
WHEN each_bid_recorded_Part2.result liKE '' AND each_bid_recorded_Part2.status NOT LIKE 'E' THEN 'active'
WHEN each_bid_recorded_Part2.result liKE each_bid_recorded_Part2.selection THEN 'WON'
WHEN each_bid_recorded_Part2.result NOT liKE each_bid_recorded_Part2.selection THEN 'LOST'
END AS result
FROM each_bid_recorded_Part2 WHERE each_bid_recorded_Part2.username LIKE '" . $_SESSION['username'] . "'

";

$qry .= " ORDER BY timelive DESC";


//for pagination
if(isset($_GET['starting'])&& !isset($_REQUEST['submit'])){
$starting=$_GET['starting'];
}else{
$starting=0;
}
$recpage = 4;//number of records per page

$obj = new pagination_class($qry,$starting,$recpage);        
$result = $obj->result;



function getStyleColorForStatus($status) {
  if ($status == 'WON') {
return '#99ff99';
  }
  else if ($status == 'LOST') {
return '#ff9999';
  }
  else if ($status == 'pending') {
return '#e5e5e5';
  }
return '';
}



?>


<div>
  <div class="pageTop"><img src="images/icons/faqicon.png" width="37" height="37" align=absbottom>      Betting History</div>
    <tr>
    <td>&nbsp;</td>
    </tr>
</div>
  <div>
<p style="font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; color: #535252; text-align: left;">Check your bets with you as a last bidder.</p>
  </div>
<table width="600" border="0" cellspacing="0" cellpadding="0" style="font-size:11px; color: #535252;">
  </div>        
</div>          
        <table border="0" align="left" width="500px" padding-left="0px" style="background:#F9F9F9;">



        <tr><TD colspan="0">

        <div id="page_contents">

            <table width="98%" cellspacing="0" cellpadding="5" align="center" frame="box" rules="none" style="padding-bottom:2px; margin-bottom:0px; margin-top:3px; -webkit-box-shadow: 0 1px 10px rgba(0,0,0,.1); -moz-box-shadow: 0 1px 10px rgba(0,0,0,.1); box-shadow: 0 1px 10px rgba(0,0,0,.1); border: 1px solid #cccccc;">
            <tr style="height: 40px;">
<td width="30%" align="center" td class="winheader"><div class="glowtext">Event Start Time</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Bid Cost</div></td></td>  
<td width="35%" align="center" td class="winheader"><div class="glowtext">Market/Event</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Selection</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winnings</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Odds</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Gained Odds</div></td></td>
<td width="10%" align="center" td class="winheader"><div class="glowtext">Winning Bidder</div></td></td>
<td width="5%" align="center" td class="winheader"><div class="glowtext">Final Result</div></td></td>
            </tr>
            <?if(mysql_num_rows($result)!=0){
                $counter = $starting + 1;
                while($data = mysql_fetch_array($result)) {?>



    <tr class="initial" onMouseOver="this.className='highlight'" onMouseOut="this.className='normal'">


                    <td align="center"><font color="#333"><? echo $data['timelive']; ?></TD>
                    <td align="center">&euro; <? echo $data['bidprice']; ?></TD>        
                    <td align="left"><font color="#0070c0"><? echo $data['match_title']; ?></TD>                
                    <td align="left"><? echo $data['selection']; ?></TD>
                    <td align="center"><font color="green">&euro; <? echo $data['winnings_with_startamount']; ?></TD>
                    <td align="center"><? echo $data['odds']; ?></TD>
                    <td align="center"><? echo $data['gainedodds']; ?></TD>
                    <td align="center"><? echo $data['username']; ?></TD>
                    <td align="center" style="background-color:<?php echo getStyleColorForStatus($data['result']); ?>"><? echo $data['result']; ?></td>
                    </tr>


                <?
                    $counter ++;
                } ?>


                <tr><TD align="center" colspan="10" style="padding-bottom:1px; padding-top:10px; color:#333;"><? echo $obj->anchors; ?></TD></tr>
                <tr><TD align="center" colspan="10" style="padding-bottom:10px; padding-top:5px; color:#333;"><? echo $obj->total; ?></TD></tr>
            <?}else{?>
                <tr><TD align="center" colspan="10" style="padding-bottom:10px padding-top:10px; color:red;">No Data Found</TD></tr>
            <?}?>
            </TD></tr>
            </table>
        </div>
        </tr>
        </TD>

    </table>

pagination.js:

var xmlHttp

function pagination(page)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="myaccount_bettinghistory_sub.php";
url = url+"?starting="+page;
url = url+"&search_text="+document.form1.search_text.value;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("page_contents").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

pagination_class.php:

<?
/*
Developed by Reneesh T.K
reneeshtk@gmail.com
You can use it with out any worries...It is free for you..It will display the out put like:
First | Previous | 3 | 4 | 5 | 6 | 7| 8 | 9 | 10 | Next | Last
Page : 7  Of  10 . Total Records Found: 20
*/
class Pagination_class{
var $result;
var $anchors;
var $total;
function Pagination_class($qry,$starting,$recpage)
{
    $rst        =   mysql_query($qry) or die(mysql_error());
    $numrows    =   mysql_num_rows($rst);
    $qry         .= " limit $starting, $recpage";
    $this->result   =   mysql_query($qry) or die(mysql_error());
    $next       =   $starting+$recpage;
    $var        =   ((intval($numrows/$recpage))-1)*$recpage;
    $page_showing   =   intval($starting/$recpage)+1;
    $total_page =   ceil($numrows/$recpage);

    if($numrows % $recpage != 0){
        $last = ((intval($numrows/$recpage)))*$recpage;
    }else{
        $last = ((intval($numrows/$recpage))-1)*$recpage;
    }
    $previous = $starting-$recpage;
    $anc = "<ul id='pagination-flickr'>";
    if($previous < 0){
        $anc .= "<li class='previous-off'><<</li>";
        $anc .= "<li class='previous-off'><</li>";
    }else{
        $anc .= "<li class='next'><a href='javascript:pagination(0);'><< </a></li>";
        $anc .= "<li class='next'><a href='javascript:pagination($previous);'>< </a></li>";
    }

    ################If you dont want the numbers just comment this block############### 
    $norepeat = 4;//no of pages showing in the left and right side of the current page in the anchors 
    $j = 1;
    $anch = "";
    for($i=$page_showing; $i>1; $i--){
        $fpreviousPage = $i-1;
        $page = ceil($fpreviousPage*$recpage)-$recpage;
        $anch = "<li><a href='javascript:pagination($page);'>$fpreviousPage </a></li>".$anch;
        if($j == $norepeat) break;
        $j++;
    }
    $anc .= $anch;
    $anc .= "<li class='active'>".$page_showing."</li>";
    $j = 1;
    for($i=$page_showing; $i<$total_page; $i++){
        $fnextPage = $i+1;
        $page = ceil($fnextPage*$recpage)-$recpage;
        $anc .= "<li><a href='javascript:pagination($page);'>$fnextPage</a></li>";
        if($j==$norepeat) break;
        $j++;
    }
    ############################################################
    if($next >= $numrows){
        $anc .= "<li class='previous-off'>></li>";
        $anc .= "<li class='previous-off'>>></li>";
    }else{
        $anc .= "<li class='next'><a href='javascript:pagination($next);'>> </a></li>";
        $anc .= "<li class='next'><a href='javascript:pagination($last);'>>></a></li>";
    }
        $anc .= "</ul>";
    $this->anchors = $anc;

    $this->total = "Page : $page_showing of $total_page  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Total Records Found: $numrows";
}
}
?>

1 个答案:

答案 0 :(得分:0)

删除此

&& !isset($_REQUEST['submit'])

你没有使用它!!!