此代码应显示数据库中的图像。它还创建了一个可以正常工作的随机背景颜色。代码是一个函数,该函数发布在 index.php 中,它基本上是 html。当我将代码直接放在 index.html 中时,该函数和第一个 while 循环运行得很好。
$query = mysql_query("SELECT `image_id`, `name`, `likes` FROM `images`");
while(($row = mysql_fetch_assoc($query)) !== false){
$sql = mysql_query("SELECT * FROM images");
while($row = mysql_fetch_array($sql)){
$images_id = $row["image_id"];
$images_path = $row["path"];
$images_name = $row["name"];
$images_type = $row["type"];
$images_size = $row["size"];
$images_likes = $row["likes"];
if($images_id == $images_id){
$kiesGetal = rand(1, 6);
switch ($kiesGetal){
case 1: $randKleur = "#a4a6a2";
break;
case 2: $randKleur = "#7e8661";
break;
case 3: $randKleur = "#9faac7";
break;
case 4: $randKleur = "#80957a";
break;
case 5: $randKleur = "#e09e6d";
break;
case 6: $randKleur = "#a0dd8d";
break;
}
echo"<li style=\"background-color:$randKleur\" id=\"$images_id\" class=\"fotoFrame\">"
. "<p class=\"imagas_name\" id=\"$images_name\">$images_name</p>"
. "<p>$images_likes mensen vinden dit leuk.</p>"
. "<img class=\"images\" src='img/" . $row['name'] . "'></>" . "</li>";
}else{
echo "error";
}
}
}
};
?> `