duanguochong0397 2019-05-29 09:37
浏览 40
已采纳

从数据库获取第一行会持续刷新页面

I'm trying to get the first row from phpmyadmin. After trying to do it different ways, I thought I would ask. Right now, the problem is that it is refreshing the browser continuously.

i've tried to add a die, but I'm not very good at mysqli/php

    $sql2="SELECT * FROM stellingen WHERE REGIOID=1;";
    $records2 =  mysqli_query($con, $sql2);

    $row = mysqli_fetch_assoc($records2);

    while ($stellingen = mysqli_data_seek($records2, 0)){
        echo "<p>".$stellingen['Stelling']."</p>";
    }

I expect the php to fetch the first data. In the context of a loop where the next data will nneed to come later in the page.

some more code


<div class="stellingen">
    <div class="stelling-wrapper" id="btn1">
        <img src="images/button.svg" alt="Show more..." class="btn" id="bton">
        <p type="button" class="stelling">
<?php
    $sql2="SELECT * FROM stellingen WHERE REGIOID=1;";
    $records2 =  mysqli_query($con, $sql2);

    $row = mysqli_fetch_assoc($records2);

    while ($stellingen = mysqli_data_seek($records2, 0)){
        echo "<p>".$stellingen['Stelling']."</p>";
    }

    /*
    if ($recordscheck2 > 0){
        while ($stellingen = mysqli_fetch_assoc($records2)){
            echo "<p>".$stellingen['Stelling']."</p>";
        }
    }*/
?>
</div>
<div id="p1">
    <table id="tabel" border=1px class="data">
    <tr>
        <th>Title</th>
        <th>Source</th>
        <th>Weight</th>
        <th>Date</th>
    </tr>

<?php
$sql1="SELECT * FROM stelling WHERE stelling_iD=1;";
$records1 =  mysqli_query($con, $sql1);
$recordscheck = mysqli_num_rows($records1);

if ($recordscheck > 0){
    while ($stelling = mysqli_fetch_assoc($records1)){
        echo "<tr>";
            echo "<td>".$stelling['Title']."</td>";
            echo "<td>".$stelling['Source']."</td>";
            echo "<td>".$stelling['Wheight']."</td>";
            echo "<td>".$stelling['Timer']."</td>";
        echo "</tr>";
    }
}
?>
    </table>
</div>
  • 写回答

1条回答 默认 最新

  • dsgdfh302506 2019-05-29 09:52
    关注

    Okey, so your using mysqli_data_seek() in a while() loop, which is wrong...

    <?php
    
    if($result = mysqli_query($con, "SELECT * FROM stellingen WHERE REGIOID=1;")) {
    
        mysqli_data_seek($result, 0);
    
        $row = mysqli_fetch_assoc($result);
    
        echo "<p>{$row["Stelling"]}</p>";
    
    }
    
    ?>
    

    Should work for you.

    [Edit] I corrected my variable names.

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

报告相同问题?

悬赏问题

  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源