每页内容不变
Content per page is not changing
我的 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();?>
初看选择内容没什么问题,但是分页links
你这么写的
echo "<a href='http://daeheung.webgd.gethompy.com/?page_id=96=".$i."'>".$i."</a> ";
并试图找到这样的页码
if (isset($_GET["uid"])) { $uid = $_GET["uid"]; } else { $uid=1; };
但是你的link中没有参数uid。我想你想写类似
的东西
echo "<a href='http://daeheung.webgd.gethompy.com/?page_id=96&uid=".$i."'>".$i."</a> ";
我的 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();?>
初看选择内容没什么问题,但是分页links 你这么写的
echo "<a href='http://daeheung.webgd.gethompy.com/?page_id=96=".$i."'>".$i."</a> ";
并试图找到这样的页码
if (isset($_GET["uid"])) { $uid = $_GET["uid"]; } else { $uid=1; };
但是你的link中没有参数uid。我想你想写类似
的东西echo "<a href='http://daeheung.webgd.gethompy.com/?page_id=96&uid=".$i."'>".$i."</a> ";