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.

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

报告相同问题?

悬赏问题

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