简体   繁体   English

如何从表中获取所有条目?

[英]How to get all entries out of a table?

I'd like to build a ul by pull the content out of a SQL table. 我想通过将内容从SQL表中拉出来构建ul。 But this code does only gives me the first row. 但是这段代码只给了我第一行。 What would be the best solution to get all 10 entries? 什么是获得全部10个条目的最佳解决方案?

$query = "SELECT * FROM `activitys`";

echo '<td><ul>';

if ($result = mysqli_query($link, $query)) {

    $row = mysqli_fetch_array($result);

    echo "<li>".$row['content']."</li>";

}

echo '<td><ul>';

You need to put it in a loop, like this: 您需要将其放在一个循环中,如下所示:

while($row = mysqli_fetch_array($result)) {
    echo "<li>".$row['content']."</li>";
}

Wrap it in a while loop. 将其包装在while循环中。 That way it will keep going until the end. 这样,它将一直持续到最后。 An IF only runs once. IF仅运行一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM