estoy diseñando una pagina en php y base de datos Mysql en donde guardo una serie de imagenes, deseo crear una galeria para mostrar las fotos de una forma que muestre 4 imagenes por linea, en un total de 5 lineas por pagina.
Encontre en un viejo foro el siguiente codigo:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Bigsport.com.ve</title>
<style type="text/css">
<!--
body {
background-color: #000000;
}
-->
</style>
</head>
<body>
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="980" height="150" valign="top" bgcolor="#0000FF"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="360" valign="top" bgcolor="#FFFFFF"><blockquote>
<p><br />
<strong>Balones para Baloncesto</strong> </p>
<p><span style="text-align: left">
<?php require_once('Connections/connFlashblog.php'); ?>
<?
$base=$database_connFlashblog;
$con=mysql_connect($hostname_connFlashblog,$username_connFlashblog,$password_connFlashblog);
// Variables de Configuración -----------------------------------
// Define el numero de Filas
$n_filas=10;
//***************************************************************
$cat=$_REQUEST['id'];
$cat=8;
$fotos = array();
$sql="SELECT * FROM productos ORDER BY id ASC";
mysql_select_db ($base,$con);
$sql_exec=mysql_query($sql);
$tottal=113;
// ------------------------------------------------------------------------------------------------------------------
$vert=$tottal/$n_filas;
$vert=round($vert);
/*function npad($num, $max = 0)
{
return str_pad($num, $max, '0', STR_PAD_LEFT);
} */
?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_Recordset1 = 6;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
mysql_select_db($base, $con);
$query_Recordset1 = "SELECT * FROM productos";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $con) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
if (isset($_GET['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<?php
$a=0;// Colocando el contador horizontal en 0
$i=1;// Colocando el contador vertical en 0
$w=0;//Colocando un contador para el mensaje de "No hay articulos en esta acategoria"
while($row=mysql_fetch_assoc($Recordset1)){
$w=w+1;
if ($a==0){
echo '<tr>';
}
$a=$a+1;
$fotos[$i.'-'.$a] = $row['imagen'];
$num= $num + 1;
echo '<table width="154" border="1" align="center" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="150" height="152" valign="top"><img src="ver_producto.php?id='.$row["id"].'"; ancho=150&alto=150" width="150" height="150" border="0" /></td>
</tr>
</table>';
$r=$a;// contador remanente para listar imagenes sin exceso
if ($a >= $n_filas) {
$a=0;// reiniciando el contador horizontal
$i=$i+1;// aumentando el contador vertical
echo '</tr><td></td>';
}
if (empty($row)) {
echo"
texto de que no hay
";
break 1;}
}
?>
</table>
<table border="0" width="50%" align="center">
<tr class="Estilo6">
<td width="23%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">Primero</a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Anterior</a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Siguiente</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Último</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
<div align="left"><span class="textoTitulos2">Registros </span><span class="textoRojo"><?php echo ($startRow_Recordset1 + 1) ?></span><span class="textoTitulos2"> a </span><span class="textoRojo"><?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?></span><span class="textoTitulos2"> de</span> <span class="textoRojo"><?php echo $totalRows_Recordset1 ?></span></div>
<?php
mysql_free_result($Recordset1);
?>
</p>
<p> </p>
<p> <br />
<br />
</p>
</blockquote></td>
</tr>
<tr>
<td height="50" valign="top" bgcolor="#0000CC"><!--DWLayoutEmptyCell--> </td>
</tr>
</table>
</body>
</html>