Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/04/2011, 14:39
Avatar de laratik
laratik
 
Fecha de Ingreso: mayo-2010
Ubicación: Cali
Mensajes: 317
Antigüedad: 13 años, 10 meses
Puntos: 63
Respuesta: Mostrar imagen en celda tras obtener ruta desde base mysql mediante select

Hola plataformas, después de revisar tu código, veo que estas utilizando demasiado código dentro del manejador de eventos, para próximos proyectos, trata de que no sea así, ya que se hace muy difícil la lectura del código (a HTML lo que es de HTML y a javascript lo que es de javascript).

ERRORES

1. te falto un echo al mostrar la $imagenactual <?php echo $fotoactual; ?>

2. y mas imporatante, no estas modificando dentro del javascript para que se muestre una nueva imagen cada vez que cambias el select.

Referente a lo de tener una imagen por defecto creo que podrías manejarlo desde javascript para cuando sea index 0.

Código completo y corregido:

Código HTML:
<html> 
<head> 
<script type="text/javascript">
function r(sel) {
	if(sel.selectedIndex == 0) {
		document.getElementById("mostrar").src = "images/errorIcon.gif";
	}
	codigo.value=sel.options[sel.selectedIndex].getAttribute('codigo');
	nombre.value=sel.options[sel.selectedIndex].getAttribute('nombre');
	vinculo.value=sel.options[sel.selectedIndex].getAttribute('vinculo');
	ruta.value=sel.options[sel.selectedIndex].getAttribute('ruta');
	document.getElementById("mostrar").src = sel.options[sel.selectedIndex].getAttribute('ruta');
}

</script>
</head> 
<body> 
<ul> 
<table width="100%" border="0" align="center">
<tr>
<form name="Formulario" method="post" action="actualizalink.php" enctype="multipart/form-data">
<tr>
<td style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#930; font-weight: bold;" width="140" height="20" align="left"><span class="Estilo6"><strong>Seleccionar Link</strong></span></td>
<td width="371">
<?php
$link = mysql_connect("localhost","root","******");
mysql_query("SET NAMES 'utf8'"); //selecciona el cotejamiento de la base de datos
mysql_select_db("universidad",$link);
$cadena = mysql_query("SELECT * FROM links ORDER BY id ASC",$link);
?>
<select name="selecnot" id="selecnot" onChange="r(this)">
<option value="0" responsable="">Seleccione Link </option>
<?php 
while ($row = mysql_fetch_assoc($cadena))
{
?>
<option value="<?php echo $row['id']?>"codigo="<?php echo $row['id']?>"nombre="<?php echo $row['nombre']?>"vinculo="<?php echo $row['vinculo']?>"ruta="<?php echo $row['ruta']?>" > <?php echo $row['nombre']?>
</option>
<?PHP
// GUARDO LA RUTA DE LA IMAGEN SELECCIONADA
$fotoactual = $row['ruta'];
}
?>
</select>
<label>
<input name="codigo" type="hidden" id="codigo" />
</label>
</td>
</tr>
<!-- AQUI QUIERO QUE SE MUESTRE LA IMAGEN QUE CORRESPONDE A LA OPCION ELEGIDA DEL SELECT --> 
<tr>
<td style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#930; font-weight: bold;" width="140" align="left">Imagen Actual</td>
<td align="left">
<img id="mostrar" name="fotolink" id="fotolink" src='images/errorIcon.gif' alt="IMAGEN LINK" height='80' width='180' align='center' />
</td>
</tr>
<!-- fin de la muestra de imagen -->

<tr>
<td style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#930; font-weight: bold;" width="140" align="left">Nombre Link</td>
<td align="left"><input name="nombre" id="nombre" type="text" size="50" maxlength="50" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; color:#F60;" onChange="ValNombre(this.value);"/></td>
</tr>
<tr>
<td style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#930; font-weight: bold;" align="left">Vinculo</td>
<td align="left"><input name="vinculo" id="vinculo" type="text" size="50" maxlength="50" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; color:#F60;" onChange="ValVinculo(this.value);"/></td>
</tr>
<tr>
<td style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#930; font-weight: bold;" align="left">Ruta Imagen</td>
<td align="left">
<input name="ruta" type="text" id="ruta" value="" size="50" maxlength="50" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; color:#F60;" />
</td>
</tr>
<tr>
<td style="font-family:Tahoma, Geneva, sans-serif; font-size:12px; color:#930; font-weight: bold;" width="292" align="left">Seleccionar nueva Imagen</td>
<td align="left"><input type="file" name="imagen" size="36"></td>
</tr>
<tr>
<td height="40" align="center"><input type="submit" name="act" value="Actualizar Link"/></td>
</tr>
</form>
</tr>
</table>
</body> 
</html> 
Creo que la parte de $fotoactual = $row['ruta']; sobra si lo piensas manejar con una imagen por defecto.
__________________
Programar apasiona y lo que apasiona es un arte, por lo tanto programar es un arte.

Quiero karma para en mi próxima vida ser un billonario bien dotado con alas.