Pregunta:
Fecha: 31-05-2019 05:37:44
(En Español)
Tengo 10 input en los cuales si no agrego consecutivamente no me los muestra (si me los agrega)
Si agrego datos en el 1 y el 2 y dejo vació el 3 y 4 ya del 5 en adelante no me muestra informacion
Este es mi codigo
Votos: 0 - Respuestas: 2 - Vistas: 12 Compartir en: Google Facebook Twitter LinkedIn Link
Ayuda con la Automatizacion de codigo (ciclos)[No resuelta]
Hola amigos tengo el siguiente código, pero no me funciona como quisieraTengo 10 input en los cuales si no agrego consecutivamente no me los muestra (si me los agrega)
Si agrego datos en el 1 y el 2 y dejo vació el 3 y 4 ya del 5 en adelante no me muestra informacion
Este es mi codigo
$contenedores="";
while($row = mysqli_fetch_array($result)) {
if($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>'' and $row["Contenedor8"]<>'' and $row["Contenedor9"]<>'' and $row["Contenedor10"]<>''){
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"] . " - " . $row["Contenedor4"] . " - " . $row["Contenedor5"] . " - " . $row["Contenedor6"] . " - " . $row["Contenedor7"] . " - " . $row["Contenedor8"] . " - " . $row["Contenedor9"] . " - " . $row["Contenedor10"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>'' and $row["Contenedor8"]<>'' and $row["Contenedor9"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"] . " - " . $row["Contenedor4"] . " - " . $row["Contenedor5"] . " - " . $row["Contenedor6"] . " - " . $row["Contenedor7"] . " - " . $row["Contenedor8"] . " - " . $row["Contenedor9"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>'' and $row["Contenedor8"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"] . " - " . $row["Contenedor4"] . " - " . $row["Contenedor5"] . " - " . $row["Contenedor6"] . " - " . $row["Contenedor7"] . " - " . $row["Contenedor8"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"] . " - " . $row["Contenedor4"] . " - " . $row["Contenedor5"] . " - " . $row["Contenedor6"] . " - " . $row["Contenedor7"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"] . " - " . $row["Contenedor4"] . " - " . $row["Contenedor5"] . " - " . $row["Contenedor6"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"] . " - " . $row["Contenedor4"] . " - " . $row["Contenedor5"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"] . " - " . $row["Contenedor4"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"] . " - " . $row["Contenedor3"];
}elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'')
{
$contenedores=$row["Contenedor1"] . " - " . $row["Contenedor2"];
}else
{
$contenedores=$row["Contenedor1"];
}Votos: 0 - Respuestas: 2 - Vistas: 12 Compartir en: Google Facebook Twitter LinkedIn Link
Respuestas:
-
Fecha: 02-06-2019 14:51:17 Te sugiero expresar la condición de alguna otra manera... es muy difícil de seguir el código así como está...
Algo que podrías hacer es recorrer los campos con un for. Aprovecha que los índices son strings y haz algo como:
$lastNonEmpty = 1; for ( $i = 2; $i < 10; $i++ ) { $key = 'Contenedor' . $i; if ( $row[ $key ] <> '' ) { $lastNonEmpty = $i; } } $contenedores = ""; for ( $i = 1; $i < $lastNonEmpty; $i ++ ) { $contenedores .= $row["Contenedor" . $i] . ' - '; }Votos: 0 - Link respuesta -
Fecha: 05-06-2019 11:10:45 Tal vez esto te sirva:
<?php $arregloContenedores = []; $contenedorPrefijo = 'Contenedor'; while ($row = mysqli_fetch_array($result)) { foreach (range(1, 8) as $indice) { if ($row[$contenedorPrefijo . $indice] === '') { break 2; } $arregloContenedores[] = $row[$contenedorPrefijo . $indice]; } } $contenedores = implode(' - ', $arregloContenedores);Votos: 0 - Link respuesta
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión
