- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的分页代码,在页面底部,显示页码但 ahref 链接不起作用。谁能告诉我哪里出错了。我希望你不需要 css 文件。
另请注意,分页链接(ahref 链接)是第一次创建,但当我从一个页面移动到另一个页面时,链接会消失。 (我没有包含连接字符串。)
<html>
<head>
<link href="pagin.css" rel="stylesheet" type="text/css" />
</head>
<?php
/*
Place code to connect to your DB here.
*/
include('config.php'); // include your code to connect to DB.
$tbl_name="data"; //your table name
// How many adjacent pages should be shown on each side?
$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
echo $query;
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
/* Setup vars for query. */
$targetpage = "page3.php"; //your file name (the name of this file)
$limit = 4;
//how many items to show per page
$page = isset($_GET['page']);
if($page)
$start = ($page - 1) * $limit;
//first item to display on this page
else
$start = 0;
//if no page var is given, set start to 0
/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql) or die($sql. "<br>". mysql_error());
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\">previous</a>";
else
$pagination.= "<span class=\"disabled\">previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">next</a>";
else
$pagination.= "<span class=\"disabled\">next</span>";
$pagination.= "</div>\n";
}
?>
<?php
while($row = mysql_fetch_assoc($result))
{
// Your while loop here
$title = $row['title'];
$link = $row['link'];
$region = $row['region'];
$sector = $row['sector'];
$theme = $row['theme'];
echo "<tr>";
echo "<td>";
echo "<div class='admonition'>";
echo "<div class='admonition-title'>";
echo "<a href=$link><h3>$title<h3></a>";echo "</div>"; echo "</div>";
echo "<h4>Sector: $sector Theme: $theme
<br> Region: $region <hr> </td>";
echo "</tr>";
}
?>
<?php echo $pagination; ?>
最佳答案
通过这个:
echo "<h4>Sector: $sector Theme: $theme
<br> Region: $region <hr> </td>";
echo "</tr>";
您的标签似乎没有结束标签。
改用这个
echo "<h4>Sector: $sector Theme: $theme
<br> Region: $region </h4><hr> </td>";
echo "</tr>";
它会破坏您的代码。此行后回显的分页无法显示分页链接。它可能迷失在多余的不间断空格中 nbsp;为什么不使用 css float 来减少该行的标记?
[更新 3.0]
这样做并让我知道您找到了什么(注意整数转换)。出于某种原因,这仅在我将 $page 转换为整数时有效。
<?php
$total_rows = 20;
$selected_row = mt_rand(0, $total_rows);
/*
Place code to connect to your DB here.
*/
//include('config.php'); // include your code to connect to DB.
$tbl_name = "data";
// How many adjacent pages should be shown on each side?
$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name";
//echo $query;
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
/* Setup vars for query. */
$targetpage = "page3.php"; //your file name (the name of this file)
//UPDATE 2.0
//Create the lines below to get k=world&x=9&y=2 and include links. Please see changes in link below:
/*
$k = ((isset($_GET['k']))? "&k=".$_GET['k'] : "" );
$x = ((isset($_GET['x']))? "&x=".$_GET['x']: "" );
$y = ((isset($_GET['y']))? "&y=".$_GET['y'] : "" );
$query_string = $k.$x.$y;
*/
//UPDATE 3.0
//MORE DYNAMIC should you decide to change the url parameters used.
$q = $_SERVER['QUERY_STRING'];
if($q != ""){
$q_a = explode('&', $q);
$q_b = array();
$q_c = array();
$link = "";
foreach($q_a as $param){
$q_b[] = explode('=', $param);
foreach($q_b as $key => $value){
$q_c[$value[0]] = $value[1];
}
}
unset($q_c['page']);
}
foreach($q_c as $key => $value){
$link .= "&";
$link .= $key.'='.$value;
}
$query_string = $link;
$limit = 4;
//how many items to show per page
$page = isset($_GET['page']);
$page = $this->uri->segment(3);
if ($page)
$start = ($page - 1) * $limit;
//first item to display on this page
else
$start = 0;
//if no page var is given, set start to 0
/* Get data. */
$sql = "SELECT * FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql) or die($sql . "<br>" . mysql_error());
/* Setup page vars for display. */
if ($page == 0)
$page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages / $limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if ($lastpage > 1) {
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev{$query_string}\">previous</a>";
else
$pagination.= "<span class=\"disabled\">previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) { //not enough pages to bother breaking it up
for ($counter = 1; $counter <= $lastpage; $counter++) {
if ($counter == (int) $page) {
$pagination.= "<span class=\"current\">$counter</span>";
} else {
$pagination.= "<a href=\"$targetpage?page=$counter{$query_string}\">$counter</a>";
}
}
} elseif ($lastpage > 5 + ($adjacents * 2)) { //enough pages to hide some
//close to beginning; only hide later pages
if ($page < 1 + ($adjacents * 2)) {
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) {
if ($counter == (int) $page) {
$pagination.= "<span class=\"current\">$counter</span>";
} else {
$pagination.= "<a href=\"$targetpage?page=$counter{$query_string}\">$counter</a>";
}
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1.$query_string\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage{$query_string}\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif ($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
$pagination.= "<a href=\"$targetpage?page=1{$query_string}\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2{$query_string}\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter{$query_string}\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1{$query_string}\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage{$query_string}\">$lastpage</a>";
}
//close to end; only hide early pages
else {
$pagination.= "<a href=\"$targetpage?page=1{$query_string}\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2{$query_string}\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter{$query_string}\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next{$query_string}\">next</a>";
else
$pagination.= "<span class=\"disabled\">next</span>";
$pagination.= "</div>\n";
}
?>
<?php
while ($row = mysql_fetch_assoc($result)) {
// Your while loop here
$title = $row['course_title'];
$link = $row['course_description'];
$region = $row['course_fee'];
$sector = $row['diploma_fee'];
$theme = $row['course_duration'];
/*
$title = $row['title'];
$link = $row['link'];
$region = $row['region'];
$sector = $row['sector'];
$theme = $row['theme'];
*/
echo "<tr>";
echo "<td>";
echo "<div class='admonition'>";
echo "<div class='admonition-title'>";
echo "<a href=$link><h3>$title<h3></a>";
echo "</div>";
echo "</div>";
echo "<h4>Sector: $sector Theme: $theme
<br> Region: $region <hr> </td>";
echo "</tr>";
}
?>
<?php echo $pagination; ?>
除此之外,在我看来一切正常。
关于php - 使用 PHP 的分页代码中缺少 Ahref 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15190503/
我正在尝试在 map 上绘制一些疾病事件数据的位置。 我用它来导入数据: ByTown% addProviderTiles("CartoDB.Positron")%>% addPolygons
我有一个文件调用 find.js,我使用 node find.js 运行,我的节点是版本 10 我不知道为什么我无法使用 async await。 const axios = require("axi
我有一个项目作为引用添加到 System.Web。 但是,它似乎无法获取 HttpContext。这样做: Imports System.Web _ApplicationBase = HttpCont
在互联网上找到这段代码,出于某种原因它缺少 while 循环逻辑“while(i....)”,虽然我找到了 PigLatin* 问题的其他可行解决方案,但我真的很想了解这个正在工作。 *PigLati
我工作了一整天来运行 Xampp 并在其上安装 TYPO3。现在我登录到后端,但没有显示许多管理模块,例如模板、访问等。 - 一定是我做错了什么,但我不知道。 these are the module
你好 我有编译这个问题 \begin{equation} J = \sum_{j=1}^{C} \end{equation} 我不断收到错误 missing $ inserted 这很奇怪,因
我正在尝试使用 SQLite CLI,但无法获得 generate_series功能来工作。我可以按照文档中的建议使用递归 CTE 对其进行模拟,但我似乎无法获得该链接中的任何示例。这是我的 sess
我目前正在开发我想要的软件,而软件正在安装,它可以在后台为软件创建 native 图像。 我正在考虑使用 NGEN 并将进程优先级设置为低,因为我不希望它消耗 100% CPU。但是我发现我的计算机上
我想使用 Xcodes Instruments 进行 UI 自动化测试。但似乎缺少“自动化”。我怎样才能添加这个? 最佳答案 如果您想使用自动化仪器,请使用 Xcode 7.3。 Apple 在 Xc
我目前在 JS 开发中迈出了一小步,并编写了以下链接添加器: const button = document.getElementById('button') const listdiv = docu
此代码有什么问题: NSError *error = nil; [SFHFKeychainUtils deleteItemForUsername:@"IAPNoob01" andServiceName
出于某种原因,在安装和配置(我认为)一切之后,com.adobe.utils.AGALMiniAssembler 不见了,其他一切正常。 我认为我已尽一切努力让孵化器正常工作,但显然我错过了一步。 如
我有一个名为 new 的方法。调用 new 时,我传递了一个参数,但是当我运行应用程序时,出现没有参数或参数为空的错误。 StepReader.pm package StepReader; use s
安装 gtk 1.2(包名 gtk1)和 macports chokes 在最终的 make 中,在 libintl.h 的第 440 行。 extern locale_t libintl_newlo
我用按钮创建表格。 这是javascript代码: function layersListTable(layers) { var content =''; $.each($(layer
我在使用此 javascript 时遇到此错误,任何人都可以帮我弄清楚我做错了什么吗? $(this).prepend('Check availability »'); 它给我错误 mis
我有一个独立的工具链 NDK13b、api19、llvm 3.8 编译器、arm 32 位、带有 libcpp(llvm C++ 库) 我想避免依赖 libgcc,所以我构建了 compiler-rt
我按照一些教程使用 phonegap 的条形码扫描器插件。但是当我从现有源创建一个新的 android 项目来创建条码库时 (step 6 in this page)我收到错误:“AndroidMan
我现在尝试在 Eclipse 中打开我的布局 xml 文件。我只得到错误 No XML content. Please add a root view or layout to your docume
我的 android-sdk-windows\tools 目录中缺少层次结构查看器工具。 工具链接: http://developer.android.com/guide/developing/too
我是一名优秀的程序员,十分优秀!