mysqli ignoring the first row in a table

前端 未结 4 1654
长发绾君心
长发绾君心 2021-01-25 18:14

Here is the code I\'m using to pull the data from the table:

require_once \'connect.php\';
$sql = "SELECT * FROM `db-news`";
$result = $mysqli->query         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-25 19:05

    mysqli_fetch_assoc() is the same as $result->fetch_assoc() and whenever you call this function it will advance an internal pointer to the next row. You are calling this function once just before the loop which means that you are reading the first row and ignoring the result. Remove that line.

    If you need to fetch the first line and then still loop through the whole result use foreach instead of while. For example:

    require_once 'connect.php';
    $sql = "SELECT * FROM `db-news`";
    $result = $mysqli->query($sql);
    foreach($result as $row) {
        printf($row['pagename'].' - To edit this page click here
    '); }

提交回复
热议问题