dongxiang3648 2016-07-07 17:03
浏览 42

我尝试在刷新时显示下一行,但我得到一个空白页面

Hey I try to display next row on refresh and when it arrive at last row to take it from the beginning. Here is my table

col1 row(1)
col2 row(1)
col3 row(1)
col4 row(1)
col5 row(1)

and on refresh to get

col1 row(2)
col2 row(2)
col3 row(2)
col4 row(2)
col5 row(2)

and when it arrive at last row take it from the beginning.

col1 row(1)
col2 row(1)
col3 row(1)
col4 row(1)
col5 row(1)

Here is the code so far:

<?php
include 'connect.php';
session_start();

if(isset($_SESSION["id"])){
    $_SESSION["id"] = $_SESSION["id"] + 1;
}
else{
    $_SESSION["id"] = 1;
}

$id = $_SESSION["id"];

//Your mysql connection 

$results = mysqli_query($con, "SELECT * FROM testtable WHERE `id` = $id") or die('AM error occured: ' . mysqli_error());

while($row = mysqli_fetch_array($results)){
    echo $row["content0"];
    echo "<br>";
    echo $row["content1"];
      echo "<br>";
    echo $row["content2"];
      echo "<br>";
    echo $row["content3"];
      echo "<br>";
    echo $row["content4"];
      echo "<br>";
    echo $row["content5"];

}
  • 写回答

3条回答 默认 最新

  • dtjxhf595733 2016-07-07 17:12
    关注
    <?php
    include 'connect.php';
    session_start();
    
    if(isset($_SESSION["id"])){
        $_SESSION["id"] = $_SESSION["id"] + 1;
    }
    else{
        $_SESSION["id"] = 1;
    }
    
    $id = $_SESSION["id"];
    
    //Your mysql connection 
    
    $result=mysqli_query($con,"SELECT count(id) as total from testtable");
    $data=mysqli_fetch_assoc($result);
    echo $data['total'];
    if($data['total']<$id )
    {
    $_SESSION["id"] = 1;
        $id=1;
    } 
    
    
    $results = mysqli_query($con, "SELECT * FROM testtable WHERE `id` = $id") or die('AM error occured: ' . mysqli_error());
    
    while($row = mysqli_fetch_array($results)){
        echo $row["content0"];
        echo "<br>";
        echo $row["content1"];
          echo "<br>";
        echo $row["content2"];
          echo "<br>";
        echo $row["content3"];
          echo "<br>";
        echo $row["content4"];
          echo "<br>";
        echo $row["content5"];
    
    }
    

    explanation:

    here we are getting total records and checking with current refreshed item, if greater then that we are assigning to start(1)

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行