2015-02-11 84 views
-2

所以我一直在一些項目,需要在頁面中顯示數據庫表,但由於它有很多數據我使用分頁,使它看起來更簡單,代碼完美運行,表格以正確的方式顯示。不能擺脫這個錯誤

但我有此錯誤消息:在 Ç_PHP_SELF:

注意:未定義的變量\ XAMPP \ htdocs中\ TEST2 \ test4.php 74行

是竊聽我,因爲我找不到它是什麼以及如何從我的網頁去掉它,我需要幫助的原因這個項目的最後期限會很快結束

所以這裏的代碼

<html> 
<head> 
<title>Paging Using PHP</title> 
</head> 
<body> 
<?php 
$dbhost = 'localhost'; 
$dbuser = 'root'; 
$dbpass = ''; 
$rec_limit = 10; 

$conn = mysql_connect($dbhost, $dbuser, $dbpass); 
if(! $conn) 
{ 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db('test1'); 
/* Get total number of records */ 
$sql = "SELECT count(msisdn) FROM bbs_1 "; 
$retval = mysql_query($sql, $conn); 
if(! $retval) 
{ 
    die('Could not get data: ' . mysql_error()); 
} 
$row = mysql_fetch_array($retval, 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 bill_cycle, total_bill_amount, total_outstanding_amount ". 
     "FROM bbs_1 ". 
     "LIMIT $offset, $rec_limit"; 

$retval = mysql_query($sql, $conn); 
if(! $retval) 
{ 
    die('Could not get data: ' . mysql_error()); 
} 
    echo"<table>". 
      "<tr>". 
       "<td>CYCLE</td>". 
       "<td>TOTBILL</td>". 
       "<td>OUTSTANDING</td>". 
      "</tr>"; 
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) 
{ 
    echo 
      "<tr>". 
       "<td>{$row['bill_cycle']} </td>". 
       "<td>{$row['total_bill_amount']}</td>". 
       "<td>{$row['total_outstanding_amount']}</td>". 
      "</tr>"; 

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

希望你能發現問題,

+1

不要編制'$ _PHP_SELF';它應該是'$ _SERVER ['PHP_SELF'];';並停止使用不推薦使用的'mysql_ *'函數。使用MySQLi/PDO代替 – Raptor 2015-02-11 04:25:54

+0

這個問題很明顯,它甚至向你顯示了行(74).' $ _PHP_SELF'不存在它應該是'$ _SERVER ['PHP_SELF']' – ILikeTacos 2015-02-11 04:27:13

回答

0

瀏覽器會想出做什麼給出僅問號和查詢字符串;沒有必要告訴它將它們應用到當前的URL。