2015-09-20 78 views
2

我知道它是爲了排序,但現在頁面無法正常工作。現在沒有什麼打印到我的error_logs中。PHP通過從數據庫的分頁表中排序

用戶紅酸幫助我們解決了遺漏的空白問題,並使用字符串變量而不是PHP_SELF。

一旦我按下下一個記錄,我得到:

未找到

請求的URL /surf/$index.php此服務器上找到。

此外,在嘗試 使用ErrorDocument來處理請求時遇到404未找到錯誤。

我的代碼:

<?php 
       $dbHost = "localhost"; 
       $dbUser = ""; 
       $dbPass = ""; 
       $dbName = ""; 
       $tbl_name=""; 
       $rec_limit = 20; 
       $order = "ORDER BY"; 
       $scriptname = 'index.php'; 

       mysql_connect("$dbHost", "$dbUser", "$dbPass")or die("cannot connect"); 
       mysql_select_db("$dbName")or die("cannot select DB"); 


       $sql="SELECT * FROM $tbl_name $order ".$_GET["orderby"]." ".$_GET["desc"]; 
       $result=mysql_query($sql); 
       $sql = "SELECT count(steamid) FROM $tbl_name"; 
        $result= mysql_query($sql); 

        if(! $result) 
        { 
         die('Could not get data: ' . mysql_error()); 
        } 
       $row = mysql_fetch_array($result, MYSQL_NUM); 
       $rec_count = $row[0]; 

       if(isset($_GET{'page'})) 
       { 
        $page = $_GET{'page'} + 1; 
        $offset = $rec_limit * $page ; 
       } 
       else 
       { 
        $page = 0; 
        $offset = 0; 
       } 
       $left_rec = $rec_count - ($page * $rec_limit); 
       $sql = "SELECT * ". 
       "FROM $tbl_name ". 
       "$order points DESC ". 
       "LIMIT $offset, $rec_limit"; 
       $result=mysql_query($sql); 
       while($rows=mysql_fetch_array($result)){ 

       ?> 
       <tr> 
        <td><?php echo $rows['name']; ?></td> 
        <td><?php echo $rows['points']; ?></td> 
        <td><?php echo $rows['winratio']; ?></td> 
        <td><?php echo $rows['pointsratio']; ?></td> 
        <td><?php echo $rows['finishedmaps']; ?></td> 
        <td><?php echo $rows['lastseen']; ?></td> 
       </tr> 
       </tr> 
       <?php 
       } 
       if($page > 0) 
        { 
         $last = $page - 2; 
         echo "<a href=\"$scriptname?page=$last\">Last 10 Records</a> |"; 
         echo "<a href=\"$scriptname?page=$page\">Next 10 Records</a>"; 
        } 

        else if($page == 0) 
        { 
         echo "<a href=\"$$scriptname?page=$page\">Next 10 Records</a>"; 
         } 

        else if($left_rec < $rec_limit) 
        { 
         $last = $page - 2; 
         echo "<a href=\"$$scriptname?page=$last\">Last 10 Records</a>"; 
        } 
       mysql_close(); 
       ?><?php 
       $dbHost = "localhost"; 
       $dbUser = "c1226125_ms"; 
       $dbPass = "wR(@ucrb5oG."; 
       $dbName = "c1226125_timer"; 
       $tbl_name="ck_playerrank"; 
       $rec_limit = 20; 
       $order = "ORDER BY"; 
       $scriptname = 'index.php'; 

       mysql_connect("$dbHost", "$dbUser", "$dbPass")or die("cannot connect"); 
       mysql_select_db("$dbName")or die("cannot select DB"); 


       $sql="SELECT * FROM $tbl_name $order ".$_GET["orderby"]." ".$_GET["desc"]; 
       $result=mysql_query($sql); 
       $sql = "SELECT count(steamid) FROM $tbl_name"; 
        $result= mysql_query($sql); 

        if(! $result) 
        { 
         die('Could not get data: ' . mysql_error()); 
        } 
       $row = mysql_fetch_array($result, MYSQL_NUM); 
       $rec_count = $row[0]; 

       if(isset($_GET{'page'})) 
       { 
        $page = $_GET{'page'} + 1; 
        $offset = $rec_limit * $page ; 
       } 
       else 
       { 
        $page = 0; 
        $offset = 0; 
       } 
       $left_rec = $rec_count - ($page * $rec_limit); 
       $sql = "SELECT * ". 
       "FROM $tbl_name ". 
       "$order points DESC ". 
       "LIMIT $offset, $rec_limit"; 
       $result=mysql_query($sql); 
       while($rows=mysql_fetch_array($result)){ 

       ?> 
       <tr> 
        <td><?php echo $rows['name']; ?></td> 
        <td><?php echo $rows['points']; ?></td> 
        <td><?php echo $rows['winratio']; ?></td> 
        <td><?php echo $rows['pointsratio']; ?></td> 
        <td><?php echo $rows['finishedmaps']; ?></td> 
        <td><?php echo $rows['lastseen']; ?></td> 
       </tr> 
       </tr> 
       <?php 
       } 
       if($page > 0) 
        { 
         $last = $page - 2; 
         echo "<a href=\"$scriptname?page=$last\">Last 10 Records</a> |"; 
         echo "<a href=\"$scriptname?page=$page\">Next 10 Records</a>"; 
        } 

        else if($page == 0) 
        { 
         echo "<a href=\"$$scriptname?page=$page\">Next 10 Records</a>"; 
         } 

        else if($left_rec < $rec_limit) 
        { 
         $last = $page - 2; 
         echo "<a href=\"$$scriptname?page=$last\">Last 10 Records</a>"; 
        } 
       mysql_close(); 
       ?> 
+0

你能分享哪些行產生這些錯誤嗎? – Mureinik

+0

他們在引號中。 –

+0

它是'$ _GET'嗎?或'$ _POST'? – aldrin27

回答

1

的問題,你沒有順序之間和DESC空白:

$sql="SELECT * FROM $tbl_name ORDER BY ".$_GET["orderby"].$_GET["desc"]; 

應該是:

$sql="SELECT * FROM $tbl_name ORDER BY ".$_GET["orderby"]." ".$_GET["desc"]; 

使用字符串變量代替的PHP_SELF:

$scriptname = 'myscript.php'; // OR http://domain.com/myscript.php 
echo "<a href=\"$scriptname?page=$last\">Last 10 Records</a>"; 
+0

得到了工作的順序,但現在我似乎無法得到該頁面現在的工作,現在在日誌中沒有錯誤。 檢查主帖,我編輯它。 –

+0

沒關係,我得到它的工作:)謝謝先生,我有一個變量,這是竊聽兩個$$,不能相信我沒有看到:P –

相關問題