//index页面展示,数据循环输出、检测图片输出
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Guitar Wars - Hight Scores</title>
<link rel="stylesheet" type="text/css" href="score.css">
</head>
<body>
<h2>Guitar Wars - Hight Scores</h2>
<p>Welcome, Guitar Warrior, do you have aht it takes to crack the hight score list? if so just <a href="addscore.php"> add your owen score.</a></p>
<hr/>
<?php
include 'dbc.php';
$i = 0; //设置一个计数器,当为第一个分数时突出显示
$query = "select * from guitar order by score desc,date asc";
$data = mysqli_query($dbc,$query) or die ('err:query faild');
//表格while输出
echo '<table>';
while ($row = mysqli_fetch_array($data)) {
//突出显示第一个分数
if ($i == 0) {
echo '<tr><td colspan="3" class="topscore">Top Score:'.$row['score'].'</td></tr>';
}
echo '<tr><td class="scoreinfo">';
echo '<span class="score">'.$row['score'].'</span><br/>';
echo '<strong>Name:</strong>'.$row['name'].'<br/>';
echo '<strong>Date:</strong>'.$row['date'].'<td/>';
// echo '<strong>Date:</strong>'.$row['screenshot'].'<td/>';
//检测是否有文件 进行输出 注意是路径中的文件不是数据库里的文件名
if (is_file(UPLOADPATH.$row['screenshot']) && filesize(UPLOADPATH.$row['screenshot']) > 0) {
echo '<td><img src="images/'.$row['screenshot'].'" alt="Score image" width="160px" height="100px"></td><tr/>';
}else{
echo '<td><img src="unverified.gif" alt="unverified score" width="160px" height="100px"></td><tr/>';
}
$i ++;
}
echo '</table>';
mysqli_close($dbc);
?>
</body>
</html>