hãy thử cái này:
$sql = "SELECT * FROM game";
$result = mysql_query($sql) or die(mysql_error());
$pathImg = "/images/icons/";
while ($row = mysql_fetch_array($result)) {
$pathFile = $pathImg . $row['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
echo '<img src="' . $pathFile . '">';
}
Bạn chỉnh sửa Hỏi và tôi chỉnh sửa Anwer:P
<table>
<?
if (mysql_num_rows($result) != 0) {
$counter = $starting + 1;
$pathImg = "/images/icons/";
while ($data = mysql_fetch_array($result)) {
//calculate url image
$pathFile = $pathImg . $data['sport_cat'] . ".png";
if (!file_exists($pathFile)) {
$pathFile = $pathImg . "unknown.png";
}
?>
<tr>
<td align="center"><img src="<?=$pathFile?>" alt="<?=$data['sport_cat']?>"></td>
<td align="center"><? echo $data['sport_cat']; ?></td>
<td align="center"><? echo $data['timelive']; ?></td>
<td align="center"><? echo $data['match_title']; ?></td>
<td align="center"><? echo $data['selection']; ?></td>
</tr>
<?
$counter++;
}
}
?>
</table>