Foros del Web » Programando para Internet » PHP »

[problema] mostrar 6 imagenes a la vez

Estas en el tema de [problema] mostrar 6 imagenes a la vez en el foro de PHP en Foros del Web. Tengo el siguiente codigo para mostrar imagenes de una base de datos: (Guardo las URL de 6 imagenes en la base de datos junto con ...
  #1 (permalink)  
Antiguo 29/05/2011, 18:53
 
Fecha de Ingreso: mayo-2011
Mensajes: 33
Antigüedad: 12 años, 11 meses
Puntos: 4
[problema] mostrar 6 imagenes a la vez

Tengo el siguiente codigo para mostrar imagenes de una base de datos:

(Guardo las URL de 6 imagenes en la base de datos junto con un titulo de evento y las jpg en el host)

El problema es que segun esta escrito el codigo me muestra 6 lineas con 1 foto en cada linea y cada una con su titulo. Es decir tengo 6 lineas con 6 fotos y 6 titulos

Mi idea es que me muestre solo 1 vez el titulo y las 6 fotos en una sola linea bajo el titulo. Espero haberme explicado bien.

imagenesr2011.php
Código PHP:
<?
include_once"db-cnx.php";
if(isset(
$_GET['enviar'])){
    
// asignamos los valores
    // a las variables que usaremos
    
$tituloevento $_GET['tituloevento'];
    
}
$sqlevento mysql_query("SELECT * FROM eventos order by eventos.tituloevento DESC"$db_link) or die(mysql_error);

if (
mysql_num_rows($sqlevento)) {
while(
$evento mysql_fetch_array($sqlevento)){
    
echo
'

<body bgcolor="#FFE821">
<center>
<font color="steelblue"><b>FOTOS DE ACTOS,CAMPEONATOS Y EQUIPOS</b></FONT>
</center>
<HR size="5" COLOR="NAVY">
<table>
<tr>
<td>'
.$evento[tituloevento].'</td>
</tr>
<tr>
<td>
<a href="imagesr2011/'
.$evento[fotos].'"><img src="imagesr2011/'.$evento[fotos].'"
width="100" height="100"></a>
</td>
</tr>
</table>
 
<HR size="5" COLOR="NAVY">'
;

}
} else {
    echo 
"No hay eventos para mostrar";
}
?>

El script que uso para subir las imagenes es el siguiente:

evento_imagen.php

Código PHP:
<?php 

include ('db-cnx.php'); 
if(isset(
$_POST['enviar']) && $_POST['enviar'] == 'Enviar'){ 
     
if(!empty(
$_POST['tituloevento'])){ 

            
$tituloevento $_POST['tituloevento'];     
$tituloevento strtoupper ($tituloevento); 
$date date("d-m-Y-H-i-s");
foreach (
$_FILES["foto"]["error"] as $key => $error) { 
    
//Lo de abajo significa si se sube correctamente//
    
if($error== UPLOAD_ERR_OK){ 
        
$nombre_archivo $_FILES["foto"]["name"][$key];   
$tipo_archivo $_FILES["foto"]["type"][$key];   
$tamano_archivo $_FILES["foto"]["size"][$key]; 
$temp_archivo $_FILES["foto"]["tmp_name"][$key]; 


if (!((
strpos($tipo_archivo"gif") || strpos($tipo_archivo"jpeg")) && (    $tamano_archivo 1000000)))  
{   
    echo 
"La extensión o el tamaño de los archivos no es correcta. <br><br><table><tr><td><li>Se permiten archivos .gif o .jpg<br><li>se permiten archivos de 1Mg máximo.</td></tr></table>"

else  
{   
    
$nom_img $nombre_archivo;  
      
    
$directorio 'imagesr2011/'
    if (
move_uploaded_file($temp_archivo,$directorio "/" $nom_img))  
    { 
     

            
           
// hacemos el INSERT en la BD 
$sqlInsertNot mysql_query("INSERT INTO eventos 
(tituloevento, fotos, fecha) 
VALUES ('$tituloevento', '$nom_img','$date')"

$db_link) or die(mysql_error()); 
  
 echo 
"Las fotos se publicaron correctamente"
}  



 }   
    }else{ 
    echo 
"Debe rellenar los campos vacios"

         } 
         
         
         
         


    

else{
$query mysql_query("SELECT * FROM eventos WHERE tituloevento='$tituloevento' ORDER BY ideventos DESC");
if (
mysql_num_rows($query)) {
    while (
$evento mysql_fetch_array($query)) { 
    echo
'

<p>Galeria Imagenes
<body bgcolor="#FFE821">
<div style="position: absolute; left: 80; top: 240">
<center>
<font color="steelblue"><b>FOTOS DE ACTOS,CAMPEONATOS Y EQUIPOS</b></FONT>
</center>
<HR size="5" COLOR="NAVY">
<table>
<caption align="top">'
.$evento['tituloevento'].'</caption>

<tr>
<td>
<a href="imagesr2011/'
.$evento['foto'].'"><img src="imagesr2011/'.$evento['foto'].'"
width="100" height="100"></a>
</td>
</tr>
 </table>
 
<HR size="5" COLOR="NAVY">


</div>
</body>'
;
    }
}else{
    echo 
"No hay eventos para mostrar";
}
mysql_free_result($evento); //Se borran los datos usados
}

?>  
<html> 
<head> 
<title>SISTEMA DE GESTION DE IMAGENES CLUB DE TENIS TORREVIEJA</title> 
</head> 
<H3>SISTEMA DE GESTION DE IMAGENES CLUB DE TENIS TORREVIEJA</H3> 

<h5><font color="red">***SOLO ARCHIVOS JPG O GIF, Y QUE SEAN MENORES A 1 Mg***</font></h5>
<form name="evento" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> 
<body bgcolor="#FFE821"> 
<p> 
Nombre del Evento para las imagenes<br /> 
<input type="text" name="tituloevento" size="60" /> 
</p> 
<p> 
Inserta imagenes<br /> 
<input type="file" name="foto[]" size="50" /> <BR> 
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>

</p> 

<p> 
<input type="submit" name="enviar" value="Enviar" /> 
</p> 
</form> 

<a href="imagenesr2011.php">VER IMAGENES</a> 
</body> 
</html>
Un saludo y gracias por la ayuda
  #2 (permalink)  
Antiguo 29/05/2011, 19:29
Avatar de memoadian
Colaborador
 
Fecha de Ingreso: junio-2009
Ubicación: <?php echo 'México'?>
Mensajes: 3.696
Antigüedad: 14 años, 10 meses
Puntos: 641
Respuesta: [problema] mostrar 6 imagenes a la vez

si lo que quieres es mostrar el primer titulo puedes usar una condicional.

Código PHP:
Ver original
  1. <?php
  2. include_once"db-cnx.php";
  3. if (isset($_GET['enviar'])) {
  4.     $tituloevento = $_GET['tituloevento'];
  5. }
  6. $sqlevento = mysql_query("SELECT * FROM eventos order by eventos.tituloevento DESC", $db_link) or die(mysql_error);
  7.  
  8. if (mysql_num_rows($sqlevento)) {
  9.     $i = 1;//introducimos contador
  10.     while ($evento = mysql_fetch_array($sqlevento)) {
  11. ?>
  12.         <table>                
  13.             <tr>                
  14.                 <td><?php if ($i == 1) {//si el contador dice que es el primer ciclo
  15.             echo $evento['tituloevento'];//ponemos el titulo
  16.         } ?></td>        
  17.             </tr>                
  18.             <tr>                
  19.                 <td>                
  20.                     <a href="imagesr2011/'.$evento[fotos].'"><img src="imagesr2011/'.$evento[fotos].'"                
  21.                                                                   width="100" height="100"></a>                
  22.                 </td>                
  23.             </tr>                
  24.         </table>        
  25. <?php
  26.         $i++;
  27.     }
  28. } else {
  29.     echo "No hay eventos para mostrar";
  30. }
  31. ?>
  #3 (permalink)  
Antiguo 30/05/2011, 03:00
 
Fecha de Ingreso: mayo-2011
Mensajes: 33
Antigüedad: 12 años, 11 meses
Puntos: 4
Respuesta: [problema] mostrar 6 imagenes a la vez

Gracias memoadian.

Esto me ha servido para solucionar lo del titulo del evento. ahora solo se muestra en la primera linea. Solo me queda solucionar lo siguiente:

Me siguen apareciendo las 6 fotos una bajo la otra en lugar de aparecer una junto a la otra. Es decir me crea una linea por registro de la base de datos. Yo quisiera que todas las fotos apareciesen en la misma linea.
Para explicarte mejor mi idea, en html seria asi:
Código HTML:
<tr> 
<td>foto1</td>
<td>foto2</td>
<td>foto3</td>
<td>foto4</td>
<td>foto5</td>
<td>foto6</td>
</tr> 
¿Como lo podria hacer con el php?
Porque lo que me devuelve la pagina ahora mismo es tal que asi
Código HTML:
<tr>
<td>foto1</td>
</tr>
<tr>
<td>foto2</td>
</tr>
<tr>
<td>foto3</td>
</tr>
<tr>
<td>foto4</td>
</tr>
<tr>
<td>foto5</td>
</tr>
<tr>
<td>foto6</td>
</tr> 
  #4 (permalink)  
Antiguo 31/05/2011, 05:17
 
Fecha de Ingreso: mayo-2011
Mensajes: 33
Antigüedad: 12 años, 11 meses
Puntos: 4
Respuesta: [problema] mostrar 6 imagenes a la vez

He modificado el codigo para intentar sacar lo que queria las 6 fotos en fila, pero no lo consigo. me devuelve 6 filas, la primera sin fotos, la segunda con 1 foto, la tercera con 2 fotos, la cuarta con 3 fotos, la quinta con 4 fotos y la sexta con 5 fotos.
No se que hago mal:

Código PHP:
<?
include_once"db-cnx.php";
if(isset(
$_GET['enviar'])){
    
// asignamos los valores
    // a las variables que usaremos
    
$tituloevento $_GET['tituloevento'];
    
    
}
$sqlevento mysql_query("SELECT tituloevento, fotos FROM eventos order by ideventos DESC"$db_link) or die(mysql_error);

if (
mysql_num_rows($sqlevento)){
    
        
while(
$evento mysql_fetch_array($sqlevento)){
$fotos[] = $evento[fotos]; 
$numfotos count($evento[fotos]);
$valor 6;
?>    


<body bgcolor="#FFE821">
<center>
<font color="steelblue"><b>FOTOS DE ACTOS,CAMPEONATOS Y EQUIPOS</b></FONT>
</center>
<HR size="5" COLOR="NAVY">
<?
echo"<table>";

echo
"<tr>";
if(
$numfotos $valor){ 
            echo 
"<tr>"
         }
         echo 
"<td width='' height=''><a href='imagesr2011/$fotos[1]'>"
        echo 
"<img src='imagesr2011/$fotos[1]' width='100' height='100'"
        echo 
" border=0>"
        echo 
""
        echo 
"</td>";
        echo 
"<td width='' height=''><a href='imagesr2011/$fotos[2]'>"
        echo 
"<img src='imagesr2011/$fotos[2]' width='100' height='100'"
        echo 
" border=0>"
        echo 
""
        echo 
"</td>";
        echo 
"<td width='' height=''><a href='imagesr2011/$fotos[3]'>"
        echo 
"<img src='imagesr2011/$fotos[3]' width='100' height='100'"
        echo 
" border=0>"
        echo 
""
        echo 
"</td>";
        echo 
"<td width='' height=''><a href='imagesr2011/$fotos[4]'>"
        echo 
"<img src='imagesr2011/$fotos[4]' width='100' height='100'"
        echo 
" border=0>"
        echo 
""
        echo 
"</td>";
        echo 
"<td width='' height=''><a href='imagesr2011/$fotos[5]'>"
        echo 
"<img src='imagesr2011/$fotos[5]' width='100' height='100'"
        echo 
" border=0>"
        echo 
""
        echo 
"</td>";
        echo 
"<td width='' height=''><a href='imagesr2011/$fotos[6]'>"
        echo 
"<img src='imagesr2011/$fotos[6]' width='100' height='100'"
        echo 
" border=0>"
        echo 
""
        echo 
"</td>";
        if(
$numfotos >= $valor){// si es mayor o igual añadimos </TR> 
            
echo "</tr>"
            
$numfotos 0;//seteamos a 0 el sumador y volvemos a empezar si quedan mas imagenes 
        
}//end if 
        
$numfotos++;
        
        echo 
"</tr>";
        echo 
"</table>"

 
echo
"<HR size='5' COLOR='NAVY'>";

}
} else {
    echo 
"No hay eventos para mostrar";
}
?>

Etiquetas: imagenes
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 02:28.