Div不在mysql结果php中

时间:2015-07-14 20:22:32

标签: php mysql echo

首先让我通过我的代码

<div class="Page_Navigation"><?php 
$sql = "SELECT id, name, banner, description, sponsor, votes, hits FROM websites"; 
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); ?>
<div class="Page_Navigation"><?
echo "<a href='index.php?page=1'>".'<'."</a> "; // Goto 1st page  
for ($i=1; $i<=$total_pages; $i++) { 
    echo "<a href='index.php?page=".$i."'>".$i."</a> "; 
}; 
echo "<a href='index.php?page=$total_pages'>".'>'."</a> "; // Goto last page
?></div>

以下是一张图片:

这就是它应该是的:

不仅如此,但链接已经死亡:

  

页=

2 个答案:

答案 0 :(得分:1)

使用mysqli_*PDO。见代码: -

尝试在div code之前移动for loop: -

<?php
error_reporting(E_ALL); // check all type of error
ini_set('display_errors',1); // display errors if any
$conn = mysqli_connect('server name','user name','password','database name') or die(mysqli_connect_error); // connect to database

$sql = "SELECT id, name, banner, description, sponsor, votes, hits FROM websites"; 
$rs_result = mysqli_query($sql) or die(mysqli_error($conn)); //run the query
$total_records = mysqli_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); 

echo "<a href='index.php?page=1'>".''."</a>"; // Go to 1st page 
echo '<div class="Page_Navigation">'; 
for ($i=1; $i<=$total_pages; $i++) { 

    echo "<a href=index.php?page=$i>$i</a>";
 }

  echo "<a href=index.php?page=$total_pages></a></div>"; // Go to last page
 ?>

答案 1 :(得分:0)

尝试移动div forfor for循环

<?php 
$sql = "SELECT id, name, banner, description, sponsor, votes, hits FROM websites"; 
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); 

echo "<a href='index.php?page=1'>".''."</a>"; // Goto 1st page 
echo '<div class="Page_Navigation">'; 
for ($i=1; $i<=$total_pages; $i++) { 
    echo '<a href="index.php?page='.$i.'">'.$i.'</a> ';
}

echo "<a href='index.php?page=$total_pages'>".''."</a></div> "; // Goto last page
?>

.css文件添加到类:

.Page_Navigation {
   padding: 5px;
   background: #dedede;
   margin: 5px;
}

或文件中的某个地方:

<style>
.Page_Navigation {
   padding: 5px;
   background: #dedede;
   margin: 5px;
}
</style>

我没有检查颜色是否匹配或距离,因此您需要更改:)