为什么我不能回声div?

时间:2018-11-03 08:46:28

标签: php sql mysqli

我有用于数据库中列表值的代码,但是当我将其添加到echo "<div>"时,它将停止工作

我的代码:

$sql = "SELECT name, size, type, username FROM Files";
        $result = $conn->query($sql);   

        if ($result->num_rows > 0)
        {
            while($row = $result->fetch_assoc()) 
            {
                echo "<div class='filediv'>";
                echo "<a href='uploads/$row['name']' download>$row['name']</a>";
                echo "<p>Size: $row['size']KB</p>";
                echo "<p>Type: $row['type']</p>";
                echo "<p>Creator: $row['username']</p>";
                echo "</div>";
                echo "<hr>";
            }
        }

2 个答案:

答案 0 :(得分:0)

您遇到语法错误

echo "<div class='filediv'>";
echo "<a href='uploads/".$row['name']."' download>".$row['name']."</a>";
echo "<p>Size:". $row['size']."KB</p>";
echo "<p>Type: ".$row['type']."</p>";
echo "<p>Creator: ".$row['username']."</p>";
echo "</div>";
echo "<hr>";

答案 1 :(得分:0)

您可以使用{}来打印html中的php变量。

echo "<div class='filediv'>";
echo "<a href='uploads/{$row['name']}' download>{$row['name']}</a>";
echo "<p>Size: {$row['size']}KB</p>";
echo "<p>Type: {$row['type']}</p>";
echo "<p>Creator: {$row['username']}</p>";
echo "</div>";
echo "<hr>";