Código PHP:
<?php
include ("conex.php");
$query="SELECT cve_prod, nombre_pro, precio_pro FROM producto ORDER BY cve_prod";
$result = mysql_query($query,$conex) or die( mysql_error() );
///////////////////////////////////
// 1 Ofertas
// 2 Novedades
// 3 Oferta Principal
// 4 Novedades Principal
// 5 Productos Principal
///////////////////////////////////
echo "<br>";
echo "<table width=500 border=0 cellspacing=0 cellpadding=0 align=center>";
$columnes = 4; # Número de columnas (variable)
if (($rows=mysql_num_rows($result))==0) {
echo "<tr><td colspan=$columnes class=\"txta\">No hay resultados en la BD.</td></tr> ";
} else {
//echo "<tr><td colspan=$columnes class=\"txta\">$rows Resultados </td></tr>";
}
for ($i=1; $row = mysql_fetch_row ($result); $i++) {
$resto = ($i % $columnes); # Número de celda del <tr> en que nos encontramos
if ($resto == 1) {echo "<tr>";} # Si es la primera celda, abrimos <tr>
echo "<td>";
echo "<table width=120 border=0 cellspacing=0 cellpadding=0 align=center class=\"tabla_prod\" >";
//// VALIDAMOS SI EXISTE LA IMAGEN ////
$ima = $row[0];
$imagen = "";
$imagen = "img_prod/";
$imagen .= $ima;
$imagen .= ".jpg";
//si existe pones la imagen, sino no
if (file_exists($imagen)){
echo "</tr><td height=90 align=center><a href=\"index.php?secc=desc&cve=",$row[0],"\"><img border=0 src=\"img_prod/",$row[0],"_s.jpg\"/></a></td> <td width=10></td> </tr>"; //IMAGEN LINK
} else {
echo "</tr><td height=90 align=center><a href=\"index.php?secc=desc&cve=",$row[0],"\"><img border=0 src=\"img_prod/no_imgen_s.jpg\"/></a></td> <td width=10></td> </tr>"; //IMAGEN LINK*/
}
//// FIN DE LA VALIDACION DE IMAGEN ////
?>