donglingyi4679 2013-08-10 02:41
浏览 91
已采纳

简单的下一页分页MYSQLI

Hi I'm trying to figure out if this will work in some sense. Right now of course it's not. I'm throwing now errors, but I'm also not getting anything outputting with the $nextLink variable..

Here is the full so we're clear how it all comes together:

<?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';
}
}

?>

and here is the snippet I'm working through.

$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';
}
}

I'm trying to select the next row by grabbing the bunch after current id and picking the next one to feed the $nextLink for the the HTML.

This was my vardump for $next

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

1条回答 默认 最新

  • dqthn68688 2013-08-10 02:51
    关注

    The reason you are not getting the desired output for the $nextLink variable is because you have enclosed it in single quotes ' .

    Variables inside double quotes " get evaluated by the parser. Variables inside double quotes ' do not get evaluated by the parser and are treated as literal strings.

    Instead of this

    $nextLink = '$id';

    Use this

    $nextLink = $id; or even this will do (but is not advised ) $nextLink = "$id";

    You will get the desired output for $nextLink. Hope that helps :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)