在线讨论网站实施分页

时间:2014-04-25 12:18:27

标签: php mysql

我想在我的问答网站上实现分页。现在我正在使用函数DisplayPages($CurrentPage, $TotalPages),但它没有用。以下是我的代码..

<?php 
    $recordperpage=10;
    $select_question_total  = "select * from question";
    $result_question_total  = mysql_query($select_question_total) or die(mysql_error());
    $counting_vt=array();
    $TotalPages = array();
    while($row_question_total = mysql_fetch_array($result_question_total))
    {
        array_push($counting_vt,$row_question_total['question_id']);
    }
    $TotalPages = count($counting_vt);
    //DisplayPages($CurrentPage, $TotalPages)
    //echo $TotalPages;
    $CurrentPage = $TotalPages / $recordperpage;
    echo DisplayPages($CurrentPage,$TotalPages);
?>

以下是我用于分页的功能:

function DisplayPages($CurrentPage, $TotalPages)
{
    if($TotalPages>1)
    {
        echo "<table width=\"99%\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\" align=\"center\">
                <tr> 
                    <td align=\"left\"><B><font face=\"Verdana\" size=\"1\">Page $CurrentPage of $TotalPages</font></B></td>
                </tr>
              </table>
        <br>";

        echo "<table width=\"99%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">
                <tr> 
                    <td valign=\"top\" align=\"center\"><font face=\"verdana\" size=\"1\">";

        if($CurrentPage>1)
        {
            echo "<a href=\"javascript:submitForm('1');\" 
                        title=\"Go to first page\"
                        onmouseover=\"javascript:return window.status='Go to first page';\"
                        onmouseout=\"javascript:return window.status='';\"  class='headerlink'>First
                        </a>&nbsp;|&nbsp;
                        <a href=\"javascript:submitForm('".($CurrentPage-1)."');\" 
                        title=\"Go to previous page (".($CurrentPage-1).")\"
                        onmouseover=\"javascript:return window.status='Go to previous page (".($CurrentPage-1).")';\"
                        onmouseout=\"javascript:return window.status='';\" class='headerlink'>Previous
                        </a>&nbsp;|&nbsp;";
        }

        echo "Go to Page 
                <input type=\"text\" name=\"cpage\" size=\"3\" class=\"inputnowidth\">&nbsp
                <input type=\"button\" name=\"btngo\" class=\"but\" value=\"Go\" onclick=\"submitForm(this.form.cpage.value);\">&nbsp;&nbsp;";

        if($CurrentPage<$TotalPages)
        {
            echo "<a href=\"javascript:submitForm('".($CurrentPage+1)."');\" 
                        title=\"Go to next page (".($CurrentPage+1).")\"
                        onmouseover=\"javascript:return window.status='Go to next page (".($CurrentPage+1).")';\"
                        onmouseout=\"javascript:return window.status='';\" class='headerlink'>Next
                        </a>&nbsp;|&nbsp;
                        <a href=\"javascript:submitForm('".$TotalPages."');\" 
                        title=\"Go to last page\"
                        onmouseover=\"javascript:return window.status='Go to last page';\"
                        onmouseout=\"javascript:return window.status='';\" class='headerlink'>Last
                    </a>";
        }

        echo "</font></td>
                </tr>
                </table><br>";
    }
}

0 个答案:

没有答案