我的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 :(得分:1)
首先看一下选择内容但使用分页链接没有任何问题 你写那样的东西
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> ";