我是一个学生(非常新的PHP)试图动态地改变每个"鱼"在数据库中的背景颜色,但在此之前,我需要尝试静态地改变背景,然而,我甚至不能这样做。我试过在引号周围不使用引号、引号和转义字符,但无济于事。
PHP/HTML<html>
<head>
<title>Dinosaurs</title>
</head>
<body>
</body>
<?php
include 'connection.php';
$query = "SELECT Name FROM `fish` WHERE FishTypeID = 4";
if (!$result = $mysqli->query($query)){
echo "Sorry, the website is experiencing problems.";
echo "Error: Your query failed to execute and here is why: 'n";
echo "Errno: " . $mysqli->errno . "'n";
echo "Error: " . $mysqli->error . "'n";
exit;
}
while ($row = mysqli_fetch_row($result)) {
print("<div background-color = '"blue'">
<h4>");
foreach ($row as $key => $value) {
print($value . "
<svg height = 64 width = 80>
<polygon points='1 31, 6 42, 1 47,26 63,60 50,80 64, 72 39, 80 16,60 28,26 17' />
<circle cx='20' cy='32' r='5' stroke='white' stroke-width='3' fill='black' />
</svg>");
}
print("</h4></div>");
}
?>
<h1>dinosaurs</h1>
</html>
感谢大家的帮助!原来我用的是"="而不是":"作为我的background-color赋值。