sql >> Base de Datos >  >> RDS >> Mysql

Muestre una imagen específica según el texto específico en la tabla MySQL usando PHP

prueba esto:

$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 . '">';
}

Tu editas Ask y yo edito 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>