Pregunta:
Fecha: 12-09-2017 05:47:32
(En Español)
este el codigo
while ($row=mysqli_fetch_array($consulta))
{
echo '<img src="'.$row["foto"].'" width="100" heigth="100" border="1" solid="black"/><br><br>';
?>
<tr>
<td><?php echo $row['nombres'];?></td>
<td><?php echo $row['apellido'];?></td>
<td><?php echo $row['cedula'];?></td>
<td><?php echo $row['fecha_nac'];?></td>
<td><?php echo $row['telefono'];?></td>
<td><?php echo $row['celular'];?></td>
<td><?php echo $row['sexo'];?></td>
<td><?php echo $row['correo'];?></td>
<td><?php echo $row['year_egreso'];?></td>
<td><?php echo $row['empresa_lab'];?></td>
<td><?php echo $row['cargo'];?></td>
<td><?php echo $row['direccion_emp'];?></td>
<td><?php echo $row['facultad_egre'];?></td>
<td><?php echo $row['carrera_egre'];?></td>
</tr>
<?php
}
else
{
echo "<script>alert('No existe la cedula de este egresado.')</script>";
echo "<script>window.location='consulta.html'</script>";
}
mysqli_close($conexion);
Votos: -1 - Respuestas: 6 - Vistas: 12 Compartir en: Google Facebook Twitter LinkedIn Link
como solucionar este error, syntax error, unexpected 'else' (T_ELSE) [Resuelta]
como puedo solucionar este error y graciaseste el codigo
while ($row=mysqli_fetch_array($consulta))
{
echo '<img src="'.$row["foto"].'" width="100" heigth="100" border="1" solid="black"/><br><br>';
?>
<tr>
<td><?php echo $row['nombres'];?></td>
<td><?php echo $row['apellido'];?></td>
<td><?php echo $row['cedula'];?></td>
<td><?php echo $row['fecha_nac'];?></td>
<td><?php echo $row['telefono'];?></td>
<td><?php echo $row['celular'];?></td>
<td><?php echo $row['sexo'];?></td>
<td><?php echo $row['correo'];?></td>
<td><?php echo $row['year_egreso'];?></td>
<td><?php echo $row['empresa_lab'];?></td>
<td><?php echo $row['cargo'];?></td>
<td><?php echo $row['direccion_emp'];?></td>
<td><?php echo $row['facultad_egre'];?></td>
<td><?php echo $row['carrera_egre'];?></td>
</tr>
<?php
}
else
{
echo "<script>alert('No existe la cedula de este egresado.')</script>";
echo "<script>window.location='consulta.html'</script>";
}
mysqli_close($conexion);
Votos: -1 - Respuestas: 6 - Vistas: 12 Compartir en: Google Facebook Twitter LinkedIn Link
Respuestas:
-
Fecha: 12-09-2017 06:42:09 Supongo que te falta cerrar una llave mas luego del `while` asumiendo que tienes un `if` mas arriba
<?php if (true /* o algun if que tengas por aca mas arriba */ ) { while ($row = mysqli_fetch_array($consulta)) { echo '<img src="' . $row["foto"] . '" width="100" heigth="100" border="1" solid="black"/><br><br>'; ?> <tr> <td><?php echo $row['nombres']; ?></td> <td><?php echo $row['apellido']; ?></td> <td><?php echo $row['cedula']; ?></td> <td><?php echo $row['fecha_nac']; ?></td> <td><?php echo $row['telefono']; ?></td> <td><?php echo $row['celular']; ?></td> <td><?php echo $row['sexo']; ?></td> <td><?php echo $row['correo']; ?></td> <td><?php echo $row['year_egreso']; ?></td> <td><?php echo $row['empresa_lab']; ?></td> <td><?php echo $row['cargo']; ?></td> <td><?php echo $row['direccion_emp']; ?></td> <td><?php echo $row['facultad_egre']; ?></td> <td><?php echo $row['carrera_egre']; ?></td> </tr> <?php } } else { echo "<script>alert('No existe la cedula de este egresado.')</script>"; echo "<script>window.location='consulta.html'</script>"; } mysqli_close($conexion);Votos: 0 - Link respuesta -
Fecha: 12-09-2017 06:57:23 personalmente no me gusta mezclar php y html, prefiero usar plantillas, en todo caso al menos quedaria algo mejor asi:
<?php if (true /* o algun if que tengas por aca mas arriba */ ) { while ($row = mysqli_fetch_array($consulta)) { echo '<img src="' . $row["foto"] . '" width="100" heigth="100" border="1" solid="black"/><br><br>'; echo "<tr>"; echo "<td>$row[nombres]</td>"; echo "<td>$row[apellido]</td>"; echo "<td>$row[cedula]</td>"; echo "<td>$row[fecha_nac]</td>"; echo "<td>$row[telefono]</td>"; echo "<td>$row[celular]</td>"; echo "<td>$row[sexo]</td>"; echo "<td>$row[correo]</td>"; echo "<td>$row[year_egreso]</td>"; echo "<td>$row[empresa_lab]</td>"; echo "<td>$row[cargo]</td>"; echo "<td>$row[direccion_emp]</td>"; echo "<td>$row[facultad_egre]</td>"; echo "<td>$row[carrera_egre]</td>"; echo "</tr>"; } } else { echo "<script>alert('No existe la cedula de este egresado.')</script>"; echo "<script>window.location='consulta.html'</script>"; } mysqli_close($conexion);
Pd.: Esa etiqueta IMG me parece que esta mal ubicada, si estas dentro de una tabla deberia estar en un TD o TH, caso contrario te dara lio en varios navegadores. Votos: 2 - Link respuesta -
Fecha: 12-09-2017 10:35:47 hola y gracias por contestar y no hay un "if"
codigo completo php
<?php
$cedula =$_POST['cedula'];
$conexion=mysqli_connect("localhost","root","","egresado") or
die("Problemas en la conexion");
mysqli_select_db($conexion,'egresado') or
die("Problemas en la selección de la base de datos");
$consulta=mysqli_query($conexion,"select pe.nombres, pe.apellido, pe.cedula, pe.fecha_nac, pe.telefono, pe.celular, pe.sexo, pe.correo, pe.year_egreso, pe.empresa_lab, pe.cargo, pe.direccion_emp, pe.foto, fa.facultad_egre, ca.carrera_egre
FROM persona pe
INNER JOIN facultad fa
ON fa.id_facultad= pe.id_persona
INNER JOIN carrera ca
ON ca.id_carrera= fa.id_facultad
where pe.cedula= '$cedula'") or
die("Problemas en el select:".mysqli_error($conexion));
while ($row=mysqli_fetch_array($consulta))
{
echo '<img src="'.$row["foto"].'" width="100" heigth="100" border="1" solid="black"/><br><br>';
?>
<tr>
<td><?php echo $row['nombres'];?></td>
<td><?php echo $row['apellido'];?></td>
<td><?php echo $row['cedula'];?></td>
<td><?php echo $row['fecha_nac'];?></td>
<td><?php echo $row['telefono'];?></td>
<td><?php echo $row['celular'];?></td>
<td><?php echo $row['sexo'];?></td>
<td><?php echo $row['correo'];?></td>
<td><?php echo $row['year_egreso'];?></td>
<td><?php echo $row['empresa_lab'];?></td>
<td><?php echo $row['cargo'];?></td>
<td><?php echo $row['direccion_emp'];?></td>
<td><?php echo $row['facultad_egre'];?></td>
<td><?php echo $row['carrera_egre'];?></td>
</tr>
<?php
}
else
{
echo "<script>alert('No existe la cedula de este egresado.')</script>";
echo "<script>window.location='consulta.html'</script>";
}
mysqli_close($conexion);
?> Votos: 0 - Link respuesta -
Fecha: 12-09-2017 11:24:52 Entonces si tu objetivo es saber si la consulta devolvio resultados si deberias tener un ´if´, podrias usar mysqli_num_rows:
http://php.net/manual/es/mysqli-result.num-rows.php
if (mysqli_num_rows($consulta) > 0) { while ($row = mysqli_fetch_array($consulta)) {
ya luego de cerrar el ´while´ tambien cierras el ´if´, codigo completo modificado:
<?php $cedula = $_POST['cedula']; $conexion = mysqli_connect("localhost", "root", "", "egresado") or die("Problemas en la conexion"); mysqli_select_db($conexion, 'egresado') or die("Problemas en la selección de la base de datos"); $consulta = mysqli_query($conexion, "select pe.nombres, pe.apellido, pe.cedula, pe.fecha_nac, pe.telefono, pe.celular, pe.sexo, pe.correo, pe.year_egreso, pe.empresa_lab, pe.cargo, pe.direccion_emp, pe.foto, fa.facultad_egre, ca.carrera_egre FROM persona pe INNER JOIN facultad fa ON fa.id_facultad= pe.id_persona INNER JOIN carrera ca ON ca.id_carrera= fa.id_facultad where pe.cedula= '$cedula'") or die("Problemas en el select:" . mysqli_error($conexion)); if (mysqli_num_rows($consulta) > 0) { while ($row = mysqli_fetch_array($consulta)) { echo '<img src="' . $row["foto"] . '" width="100" heigth="100" border="1" solid="black"/><br><br>'; ?> <tr> <td><?php echo $row['nombres']; ?></td> <td><?php echo $row['apellido']; ?></td> <td><?php echo $row['cedula']; ?></td> <td><?php echo $row['fecha_nac']; ?></td> <td><?php echo $row['telefono']; ?></td> <td><?php echo $row['celular']; ?></td> <td><?php echo $row['sexo']; ?></td> <td><?php echo $row['correo']; ?></td> <td><?php echo $row['year_egreso']; ?></td> <td><?php echo $row['empresa_lab']; ?></td> <td><?php echo $row['cargo']; ?></td> <td><?php echo $row['direccion_emp']; ?></td> <td><?php echo $row['facultad_egre']; ?></td> <td><?php echo $row['carrera_egre']; ?></td> </tr> <?php } } else { echo "<script>alert('No existe la cedula de este egresado.')</script>"; echo "<script>window.location='consulta.html'</script>"; } mysqli_close($conexion); ?>Votos: 1 - Link respuesta -
-
Fecha: 12-04-2018 17:13:22 Hola Jorge zabala me paso lo que alertaste
" Pd.: Esa etiqueta IMG me parece que esta mal ubicada, si estas dentro de una tabla deberia estar en un TD o TH, caso contrario te dara lio en varios navegadores."
pedras ayudar en donde colocarla, ya la puse fuera del php y pide identificar la variable $row, porfi
echo '<img src="'.$row["foto"].'" width="100" heigth="100" border="1" solid="black"/>
de php a html Votos: 0 - Link respuesta
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión
