面板列表Php未显示所有数据

时间:2017-06-07 03:37:14

标签: php sql list panel

我正在尝试创建一个面板列表,显示我的数据库中的某些行,但是当我试图调用它时,它只显示行中的1个数据,即使我将其限制为5。

这是我的剧本:

<?php
$link = mysqli_connect("localhost", "root", "", "test");
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "SELECT * FROM updates order by id desc limit 5";
if($result = mysqli_query($link, $sql)){
    if($list=mysqli_fetch_array($result)){
                echo "<div class=\"container\">";
        echo "<table>";
            echo "<tr>";               
            echo "</tr>";

        echo "<div class=\"col-md-4\">";
        echo "<div class=\"panel panel-primary\">";
        echo "<div class=\"panel-heading\">Updates";
        echo "</div>";
        echo "<ul class=\"list-group\">";
        echo "<li class=\"list-group-item\">";
        echo "<b><h4>{$list["updates"]}</b></h4>";
        echo "</li>";
        echo "</div>";
        echo "</div>";
        echo "</div>";
        echo "</div>";
}
        echo "</table>";
        mysqli_free_result($result);
    } else{
        echo "No records matching your query were found.";
    }
{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>

2 个答案:

答案 0 :(得分:0)

那是因为你只提取一次,在这里:

if ($list=mysqli_fetch_array($result) )

而是将它包装在这样的循环中:

$row_count = mysqli_num_rows($result);
if ($row_count <= 0)  {
    echo "No records matching your query were found.";
}
else {
    // you have results

    // panel starts here
    while ($list = mysqli_fetch_array($result)) {
        // do some magic with your results
    }
    // panel ends here
    mysqli_free_result($result);
}

我认为你有了这个想法,现在你可以做其余的事了。如果不再告诉我们。快乐的编码!

答案 1 :(得分:0)

你使用sql来获取五个数据,但你使用mysqli_fetch_array()函数只取出一行。

错误第8行;