简单的下一页分页MYSQLI

时间:2013-08-10 02:41:45

标签: php mysqli

嗨,我想弄清楚这是否会在某种意义上起作用。现在当然不是。我现在正在抛出错误,但我也没有使用$ nextLink变量输出任何内容..

这是完整的,所以我们很清楚这一切是如何结合在一起的:

<?php
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['id'])) {
// Connect to the MySQL database
include "includes/db_conx.php";
$id = intval($_GET['id']);// filter everything but numbers
// Use this var to check to see if this ID exists, if yes then get the product
// details, if no then exit this script and give message why


$sql = "UPDATE content SET views=views+1 WHERE ID=$id";
$update = mysqli_query($db_conx,$sql);

$sql = "SELECT * FROM content WHERE id=$id LIMIT 1";
$result = mysqli_query($db_conx,$sql);
$productCount = mysqli_num_rows($result);
//


if ($productCount > 0) {
// get all the product details
while($row = mysqli_fetch_array($result)){
$id = $row["id"];
$article_title = $row["article_title"];
$category = $row["category"];
$readmore = $row["readmore"];
$author = $row["author"];
$date_added = $row["date_added"];
$article = $row["article"];
$newDate = substr($date_added, 0, 10); 
}
} else {
echo "That item does not exist.";
exit();
}

} else {
echo "Data to render this page is missing.";
exit();
}
$sqltwo = "SELECT * FROM content WHERE id =(select min(id) from content where id > '$id') LIMIT 1";
$next = mysqli_query($db_conx,$sqltwo);
if($next > 0){
while($row = mysqli_fetch_array($next)){
$id = $row["id"];
$nextLink = '$id';
}
}

?>

这是我正在完成的片段。

$sqltwo = "SELECT * FROM content WHERE id =(select min(id) from content where id > '$id') LIMIT 1";
$next = mysqli_query($db_conx,$sqltwo);
if($next > 0){
while($row = mysqli_fetch_array($next)){
$id = $row["id"];
$nextLink = '$id';
}
}

我正在尝试通过在当前ID之后抓取一堆来选择下一行并选择下一行来为HTML提供$ nextLink。

这是我的$ next vardump

object(mysqli_result)#3 (5) {
  ["current_field"]=>
  int(0)
  ["field_count"]=>
  int(10)
  ["lengths"]=>
  NULL
  ["num_rows"]=>
  int(0)
  ["type"]=>
  int(0)
}

1 个答案:

答案 0 :(得分:0)

您未获得$nextLink变量所需输出的原因是因为您已将其括在单引号'中。

双引号"内的变量由解析器进行评估。双引号'内的变量不会被解析器评估,并被视为文字字符串。

而不是这个

$nextLink = '$id';

使用此

$nextLink = $id;甚至可以这样做(但不建议)$nextLink = "$id";

您将获得$nextLink的所需输出。希望有所帮助:)