[英]MySQL / PHP background image URL
I'm trying to setup a basic script to display the top 5 of votes from a MySQL table. 我正在尝试设置一个基本脚本来显示MySQL表中的前5个投票。 I have it displaying in the order I would like but I can't seem to add a background image.
我以我想要的顺序显示它,但似乎无法添加背景图像。 I want it to look like this:
我希望它看起来像这样:
But the output I'm getting is: 但是我得到的输出是:
My code: 我的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Top 5 Voters</title>
<meta name="description" content="">
<meta name="author" content="">
<link rel="stylesheet" href="style.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<?php
$server = "localhost";
$dbuser = "xxx";
$dbpass = "xxxx";
$dbname = "xxxx";
mysql_connect($server, $dbuser, $dbpass);
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM votes_hub_galtotals ORDER BY votes DESC LIMIT 5");
while($row = mysql_fetch_assoc($result)){
echo '<ul class="serverList">';
echo '<li class="server"><a href=""><span class="serverIcon" style="background-image: url("http://i.fishbans.com/helm/'.$row['IGN'].'/48");"></span>'.$row['IGN'].' ('.$row['votes'].')</a></li>';
echo "</ul>";
; }
?>
</body>
</html>
Even if I set it up as a static image it doesn't work. 即使我将其设置为静态图像,它也无法正常工作。
So first you query is correct and your list has the correct order. 因此,首先您查询的是正确的,并且您的列表具有正确的顺序。 Another thing is that its better if you have a complete list so put the ul before and after the while loop that you have a complete list after the iteration.
另一件事是,如果您具有完整列表,则更好,因此将ul放在while循环之前和之后,以便在迭代后获得完整列表。
echo '<ul class="serverList">';
while($row = mysql_fetch_assoc($result)){
echo '<li class="server"><a href=""><span class="serverIcon" style="background-image: url("http://i.fishbans.com/helm/'.$row['IGN'].'/48");"></span>'.$row['IGN'].' ('.$row['votes'].')</a></li>';
}
echo "</ul>";
?>
So the image is not shown because the path is not correct or the element is not visible. 由于路径不正确或元素不可见,因此未显示图像。
You set the image as background image. 您将图像设置为背景图像。 Its a span and its possble that you have not set the height and width for that element and thats why its not shown.
它的跨度及其可能尚未设置该元素的高度和宽度,这就是为什么未显示该元素的原因。 use an
<img
element to show the image. 使用
<img
元素显示图像。
And the last one is that the mysql
functions are deprecated and you should use mysqli
or PDO
with prepared statements. 最后一个是不建议使用
mysql
函数,应将mysqli
或PDO
与已准备好的语句一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.