2015-02-23 35 views
0

我在我的PHP代碼中遇到問題, 我想將我的數據從數據庫顯示爲每頁10個數據(分頁), 但是每頁的內容沒有變化,請幫助我編輯此代碼並正常工作。大每頁內容不變

<?php 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="test_display"; // Table name 
// Connect to server and select databse. 
//$uid= $_GET['uid']; 
$connection = mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

if (isset($_GET["uid"])) { $uid = $_GET["uid"]; } else { $uid=1; }; 
$start_from = ($uid-1) * 10; 

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name WHERE board_id ='5' ORDER BY date DESC LIMIT $start_from, 10" ; 
$rs_result = mysql_query ($sql,$connection); 

?> 

<table width="980" border="0" cellspacing="0" cellpadding="0" class="contact-list"> 
<colgroup> 
<col width="20"> 
<col width="150"> 
<col width="250"> 
<col width="90"> 
<col width="90"> 
<col width="80"> 
<col width="80"> 
</colgroup> 
<tr> 
<th>번호</th> 
<th>이름</th> 
<th>내용</th> 
<th>메일</th> 
<th>연락처</th> 
<th>연락처</th> 
<th>글삭제</th> 
</tr> 
<?php 
// Start looping rows in mysql database. 
while ($row = mysql_fetch_array($rs_result)) { 
?> 

<tr> 
<td><?php echo $row['uid']; ?></td> 
<td><?php echo $row['member_display']; ?></td> 
<td><?php echo $row['content']; ?></td> 
<td><?php echo $row['email']; ?></td> 
<td><?php echo $row['title']; ?></td> 
<td><?php echo $row['date']; ?></td> 
<td><a href="" onclick="return confirm('삭제 하시겠습니까?');">글삭제</a></td> 
</tr> 

<?php 

// close while loop 
} 

?> 
</table> 


<?php 
$sql = "SELECT COUNT(*) FROM $tbl_name WHERE board_id ='5' "; 
$rs_result = mysql_query($sql,$connection); 
$row = mysql_fetch_row($rs_result); 
$total_records = $row[0]; 
$total_pages = ceil($total_records /10); 

for ($i=1; $i<=$total_pages; $i++) { 
      echo "<a href='http://daeheung.webgd.gethompy.com/?page_id=96=".$i."'>".$i."</a> "; 
} 
?> 


<?php 
// close MySQL connection 
mysql_close();?> 
+0

你面對的錯誤是什麼? – 2015-02-23 07:04:31

+0

每頁內容沒有變化,但沒有顯示錯誤,內容不循環。 – akselrows 2015-02-23 07:10:13

+0

是的,你正在使用'SELECT * FROM $ tbl_name WHERE board_id ='5'ORDER BY date DESC LIMIT $ start_from,10「'這將顯示列表,你想做分頁嗎? – 2015-02-23 07:13:19

回答

1

第一眼看上去並沒有什麼不妥的內容選擇,但與 你寫simething像

echo "<a href='http://daeheung.webgd.gethompy.com/?page_id=96=".$i."'>".$i."</a> "; 

,並試圖找到這樣的

if (isset($_GET["uid"])) { $uid = $_GET["uid"]; } else { $uid=1; }; 

頁碼分頁鏈接但是,鏈接中沒有參數uid。我想你想寫點類似於

echo "<a href='http://daeheung.webgd.gethompy.com/?page_id=96&uid=".$i."'>".$i."</a> "; 
+0

哦,謝謝@SeriousDron它的工作正常現在,謝謝你 – akselrows 2015-02-23 08:05:07

+0

很高興爲你效勞,你可以將我的答案標記爲已接受,並表示感謝,有一篇文章如果有人回答,該怎麼做http://stackoverflow.com/help/someone-answers – SeriousDron 2015-02-23 08:13:40