Div 未在 mysql 结果中回显 php
Div not being echod in mysql result php
所以首先让我通过我的代码
<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>
这是一张图片:
它应该是这样的:
不仅如此,链接也失效了:
page=
尝试在 for
循环之前移动 div
<?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
文件 class:
.Page_Navigation {
padding: 5px;
background: #dedede;
margin: 5px;
}
或文件中某处:
<style>
.Page_Navigation {
padding: 5px;
background: #dedede;
margin: 5px;
}
</style>
我还没有检查颜色是否匹配或距离是否匹配,所以你需要更改它:)
使用mysqli_*
或PDO
。看代码:-
尝试在 for loop
之前移动您的 div code
:-
<?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
?>
所以首先让我通过我的代码
<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>
这是一张图片:
它应该是这样的:
不仅如此,链接也失效了:
page=
尝试在 for
循环之前移动 div
<?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
文件 class:
.Page_Navigation {
padding: 5px;
background: #dedede;
margin: 5px;
}
或文件中某处:
<style>
.Page_Navigation {
padding: 5px;
background: #dedede;
margin: 5px;
}
</style>
我还没有检查颜色是否匹配或距离是否匹配,所以你需要更改它:)
使用mysqli_*
或PDO
。看代码:-
尝试在 for loop
之前移动您的 div code
:-
<?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
?>