Foros del Web » Programando para Internet » PHP »

Imagenes asociadas a id

Estas en el tema de Imagenes asociadas a id en el foro de PHP en Foros del Web. Hola a todos. No se mucho de PHP y MYSQL, pero hago el intento. Mi consulta, ya que de codigo no se mucho es la ...
  #1 (permalink)  
Antiguo 17/04/2008, 21:50
 
Fecha de Ingreso: abril-2008
Mensajes: 11
Antigüedad: 16 años, 1 mes
Puntos: 0
Imagenes asociadas a id

Hola a todos.
No se mucho de PHP y MYSQL, pero hago el intento. Mi consulta, ya que de codigo no se mucho es la siguiente.
Tengo una base con un Id numerico ej 123456 al cual le quiero asociar varias imagenes max 10. el tema es que e visto varios script, pero nada que me pueda ayudar.
En definitiva lo que necesito es que cuando se selecciona un item (123456) me muestre las imagenes asociadas a ese Id, con un simple slideshow. No se si podria ser como 123456_1.jpg, 123456_2.jpg, etc...
Muchas Gracias.

Tengo un slideshow simple, pero no se adaptarlo a mi necesidad. Lo dejo por siaca.
Código PHP:
<?php
header
("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// siempre modificado
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0"false);
// HTTP/1.0
header("Pragma: no-cache");
require_once(
'conexion.php');
$qry=mysql_query("select * from galeria where identificador='{$_GET['identificador']}' order by id asc");
$miarrayphp=array();
$miarrayphp_txta=array();
while(
$row=mysql_fetch_assoc($qry)){
if(
$row['foto']!=""){
$miarrayphp[]='fotos/'.$row['foto'];
$miarrayphp_txta[]= ereg_replace('[[:space:]]+',' ',str_replace('"',"'",$row['contenido'])); 
}
$miarr=implode('","',$miarrayphp);
$miarrayphp_txt=implode('","',$miarrayphp_txta);
}
mysql_data_seek($qry,0); 
$imag=mysql_fetch_assoc($qry);
?>
<html>
<head>
<title>Imagenes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
var directorio="";
var indice=0;
var miarray=new Array("<?php echo $miarr?>");
var miarray_txt=new Array("<?php echo $miarrayphp_txt?>");
function precarga(){
for(i=0;i<miarray.length;i++){
eval("imagen"+i+"=new Image();");
eval("imagen"+i+".src=" + "\"" +directorio+miarray<i>+"\";");
}
}
function cambia(como){
if(como=='menos'){
indice--;}else{indice++;}
if (indice < 0) indice = miarray.length - 1;
if (indice > miarray.length-1) indice = 0;
document.getElementById("cama").src=directorio+miarray[indice];
document.getElementById('leyenda').firstChild.nodeValue = (indice+1) + " de " + miarray.length;
document.getElementById('epi').innerHTML=miarray_txt[indice];
}
</script>
</head>
<body bgcolor="c8f05e" leftmargin="0" topmargin="0">
<table width="401" cellpadding="0" cellspacing="0">
  <tr>
    <td width="399" align="left" valign="top"> 
      <table width="399" cellpadding="0" cellspacing="0">
        <tr> 
          <td width="10" rowspan="4" align="left" valign="top">&nbsp;</td>
          <td width="387" align="left" valign="top"> 
            <table width="134" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td width="17" align="right" valign="middle"><a href="javascript:cambia('menos')">&lt;&lt;</a></td>
                <td width="55" align="center" valign="middle" class="galeria"><strong><div id="leyenda">1 
                              de <?php echo mysql_num_rows($qry); ?></div></strong></td>
                <td width="17" align="left" valign="middle"><a href="javascript:cambia('mas')">&gt;&gt;</a></td>
              </tr>
          </table>          </td>
        </tr>
        
        <tr> 
          <td align="left" valign="top"><table width="385" height="208" cellpadding="0" cellspacing="0">
              <tr> 
                <td width="383" height="187" align="center" valign="middle"><script>precarga();</script><img src="<?php
          
if($imag['foto']!='' && file_exists("fotos/".$imag['foto'])){echo "fotos/".$imag['foto'];} ?>" id="cama" name="cama"></td>
              </tr>
              <tr> 
                <td height="19" align="left" valign="top">&nbsp;</td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="387" height="37" cellpadding="0" cellspacing="0">
              <tr> 
                <td class="galeria"><div id="epi" class="galeria"><?php echo $miarrayphp_txta[0]; ?></div> </td>
              </tr>
            </table></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
<?php
header
("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// siempre modificado
header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0"false);
// HTTP/1.0
header("Pragma: no-cache");
require_once(
'conexion.php');
$qry=mysql_query("select * from galeria where identificador='{$_GET['identificador']}' order by id asc");
$miarrayphp=array();
$miarrayphp_txta=array();
while(
$row=mysql_fetch_assoc($qry)){
if(
$row['foto']!=""){
$miarrayphp[]='fotos/'.$row['foto'];
$miarrayphp_txta[]= ereg_replace('[[:space:]]+',' ',str_replace('"',"'",$row['contenido'])); 
}
$miarr=implode('","',$miarrayphp);
$miarrayphp_txt=implode('","',$miarrayphp_txta);
}
mysql_data_seek($qry,0); 
$imag=mysql_fetch_assoc($qry);
?>
<html>
<head>
<title>Imagenes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
var directorio="";
var indice=0;
var miarray=new Array("<?php echo $miarr?>");
var miarray_txt=new Array("<?php echo $miarrayphp_txt?>");
function precarga(){
for(i=0;i<miarray.length;i++){
eval("imagen"+i+"=new Image();");
eval("imagen"+i+".src=" + "\"" +directorio+miarray<i>+"\";");
}
}
function cambia(como){
if(como=='menos'){
indice--;}else{indice++;}
if (indice < 0) indice = miarray.length - 1;
if (indice > miarray.length-1) indice = 0;
document.getElementById("cama").src=directorio+miarray[indice];
document.getElementById('leyenda').firstChild.nodeValue = (indice+1) + " de " + miarray.length;
document.getElementById('epi').innerHTML=miarray_txt[indice];
}
</script>
</head>
<body bgcolor="c8f05e" leftmargin="0" topmargin="0">
<table width="500" cellpadding="0" cellspacing="0">
  <tr>
    <td align="left" valign="top"> 
      <table width="500" cellpadding="0" cellspacing="0">
        <tr> 
          <td width="97" rowspan="4" align="left" valign="top">&nbsp;</td>
          <td width="385" align="left" valign="top"> 
            <table width="134" align="center" cellpadding="0" cellspacing="0">
              <tr> 
                <td width="17" align="right" valign="middle"><a href="javascript:cambia('menos')">&lt;&lt;</a></td>
                <td width="55" align="center" valign="middle" class="galeria"><strong><div id="leyenda">1 
                              de <?php echo mysql_num_rows($qry); ?></div></strong></td>
                <td width="17" align="left" valign="middle"><a href="javascript:cambia('mas')">&gt;&gt;</a></td>
              </tr>
          </table>          </td>
        </tr>
        
        <tr> 
          <td align="left" valign="top"><table width="386" height="275" cellpadding="0" cellspacing="0">
              <tr> 
                <td align="center" valign="middle"><script>precarga();</script><img src="<?php
          
if($imag['foto']!='' && file_exists("fotos/".$imag['foto'])){echo "fotos/".$imag['foto'];} ?>" id="cama" name="cama"></td>
              </tr>
              <tr> 
                <td align="left" valign="top">&nbsp;</td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="387" height="37" cellpadding="0" cellspacing="0">
              <tr> 
                <td class="galeria"><div id="epi" class="galeria"><?php echo $miarrayphp_txta[0]; ?></div> </td>
              </tr>
            </table></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>

Última edición por GatorV; 17/04/2008 a las 21:58 Razón: tags PHP
  #2 (permalink)  
Antiguo 17/04/2008, 23:38
 
Fecha de Ingreso: abril-2008
Ubicación: Querétaro, Mexico
Mensajes: 44
Antigüedad: 16 años, 1 mes
Puntos: 2
Re: Imagenes asociadas a id

hola que tal

sobre tu problema, la forma en la que lo puedes solucionar de forma facil y sencilla es:

agregando una tabla "imagenes" a tu base de datos MySQL, en esta tabla con q tenga los siguentes campos:

id con auto_increment(este no importa, pero es para q nose repitan los registros),
id_galeria (aqui metes el id con el q vas a unir tus imagenes a lo que sea q las quieras unir),
imagen (ej: imagen_0123456.jpg)


una vez q tengas eso, ahi vas a guardar todas las imagenes, digamos si quieres tener diez imagenes, metes los diez nombres de archivo, con el mismo id_galeria esas diez.

en tu php lo que vas a hacer es esto:

mandar por medio de $_GET, $_POST o lo que tu quieras el id a tu php de galeria.

Código PHP:
<?php
require_once('conexion.php');

$query mysql_query("SELECT * FROM `imagenes` WHERE `id_galeria` = '".$_GET['idGaleria']."'"); 
// lo anterior te va a devolver todas las imagenes q tengan ese id de tu galeria.

$fotos = array();
while(
$row mysql_fetch_array($queryMYSQL_ASSOC)){
  
$fotos[] = $row['imagen'];
}
?>

y asi $fotos va a ser un array con las fotos, ya depende de como lo quieras usar en tu galeria.


espero que esto te ayude!


saludos,
Carlos Alejandro
  #3 (permalink)  
Antiguo 10/05/2008, 17:50
 
Fecha de Ingreso: abril-2008
Mensajes: 11
Antigüedad: 16 años, 1 mes
Puntos: 0
Re: Imagenes asociadas a id

No entiendo como meter 10 imagenes en un mismo campo blob
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 23:05.