Pregunta:
Fecha: 07-02-2019 13:33:36
(En Español)
10 CAMPOS
A - B - C - D - E - F - G - H - I - J
4 CAMPOS
A - B - C - D - - - - - -
Linea 55
Votos: 0 - Respuestas: 4 - Vistas: 8 Compartir en: Google Facebook Twitter LinkedIn Link
Ayuda con PHP al convertir a un documento PDF[Resuelta]
Que tal comunidad tengo el siguiente problema, de una tabla convierto a un archivo pdf en el cual se ingresan de 1 a 10 campos y los separo con un guion " - " el problema es que cuando ingreso 4 campos me salen el resto de los guiones, por ejemplo:10 CAMPOS
A - B - C - D - E - F - G - H - I - J
4 CAMPOS
A - B - C - D - - - - - -
Linea 55
<?php //Get the info $idViaje=$_GET["id"]; $result=query("SELECT UCASE(C.RazonSocial) AS 'RazonSocial',UCASE(C.RFC) AS 'RFC', C.Calle,C.Colonia,UCASE(C.Municipio) AS 'Municipio',UCASE(C.Estado) AS 'Estado',C.CP,UCASE(V.Cliente) AS 'Cliente', UCASE(TC.TipoContenedor) AS 'TipoContenedor', UCASE(V.Contenedor1) AS 'Contenedor1', UCASE(V.Contenedor2) AS 'Contenedor2', UCASE(V.Contenedor3) AS 'Contenedor3', UCASE(V.Contenedor4) AS 'Contenedor4', UCASE(V.Contenedor5) AS 'Contenedor5', UCASE(V.Contenedor6) AS 'Contenedor6', UCASE(V.Contenedor7) AS 'Contenedor7', UCASE(V.Contenedor8) AS 'Contenedor8', UCASE(V.Contenedor9) AS 'Contenedor9', UCASE(V.Contenedor10) AS 'Contenedor10', UCASE(V.Referencia) AS 'Referencia', V.CartaPorte, V.Origen, V.Destino, V.Placas, V.Operador, UCASE(V.TipoOperacion) AS 'TipoOperacion', V.FechaAlta, S.Precio, S.LimitMaxRespons, S.DeducibleMaterial, S.DeducibleRobo FROM viajes V LEFT JOIN clientes C ON V.idCliente=C.idCliente LEFT JOIN Servicios S ON (V.idTipoContenedor=S.idTipoContenedor and V.idCliente=S.idCliente) LEFT JOIN TiposContenedores TC ON TC.idTipoContenedor=V.idTipoContenedor WHERE V.idViaje=".$idViaje); $row = mysqli_fetch_array($result); // Set some content to print $cant=1; 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"]<>''){ $cant=10; }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"]<>''){ $cant=9; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>'' and $row["Contenedor8"]<>''){ $cant=8; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>''){ $cant=7; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>''){ $cant=6; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>''){ $cant=5; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>''){ $cant=4; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>''){ $cant=3; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>''){ $cant=2; } $calle=""; $razonSocial=htmlentities(strtoupper($row["RazonSocial"])); $origen=htmlentities(strtoupper($row["Origen"])); $destino=htmlentities(strtoupper($row["Destino"])); $operador=htmlentities(strtoupper($row["Operador"])); $calle=htmlentities(strtoupper($row["Calle"])); $municipio=htmlentities(strtoupper($row["Municipio"])); $estado=htmlentities(strtoupper($row["Estado"])); $cliente=htmlentities(strtoupper($row["Cliente"])); $refp=htmlentities(strtoupper($row["Referencia"])); $precio=(int)$row["Precio"]; $subtotal=$precio*$cant; $iva=$subtotal*0.16; $total=$subtotal*1.16; $html = <<<EOD <div style="text-align:center;"> <img src="img/logo.jpg" with="200" alt=""> <h5>Declaración de embarque</h5> </div> <table> <tr> <td style="font-size:10px;text-align:left;line-height:20px;">CONTENEDOR:</td> <td style="font-size:10px;text-align:left;line-height:20px;" colspan="2">{$row["Contenedor1"]} - {$row["Contenedor2"]} - {$row["Contenedor3"]} - {$row["Contenedor4"]} - {$row["Contenedor5"]} - {$row["Contenedor6"]} - {$row["Contenedor7"]} - {$row["Contenedor8"]} - {$row["Contenedor9"]} - {$row["Contenedor10"]}</td> <td style="font-size:10px;text-align:left;line-height:20px;">REFERENCIA:</td> <td style="font-size:10px;text-align:left;line-height:20px;" colspan="2">{$row["CartaPorte"]}</td> </tr> ?>
Votos: 0 - Respuestas: 4 - Vistas: 8 Compartir en: Google Facebook Twitter LinkedIn Link
Respuestas:
-
Fecha: 07-02-2019 17:41:59 Hola.
Te imprime siempre los guiones porque no estas validando nada, entonces por más que los campos (contenedores) vengan vacíos siempre va haber 10 campo.
prueba con esto.
comenta todo este codigo.
/* // Set some content to print $cant=1; 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"]<>''){ $cant=10; }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"]<>''){ $cant=9; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>'' and $row["Contenedor8"]<>''){ $cant=8; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>'' and $row["Contenedor7"]<>''){ $cant=7; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>'' and $row["Contenedor6"]<>''){ $cant=6; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>'' and $row["Contenedor5"]<>''){ $cant=5; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>'' and $row["Contenedor4"]<>''){ $cant=4; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>'' and $row["Contenedor3"]<>''){ $cant=3; }elseif($row["Contenedor1"]<>'' and $row["Contenedor2"]<>''){ $cant=2; } */
Pega esto despues de la consulta sql.
$cant=0; $contenedores=""; // Obtengo la cantidad de contenedores con datos y //almaceno una variable con los datos de los contenedores, //que luego debe ser usada en la tabla. for ($i=1; $i <=10 ; $i++) { $contenedor='Contenedor'.$i; if($row[$contenedor] != ''){ $cant++; $contenedores.=(empty($contenedores))? $row[$contenedor]: ' - '.$row[$contenedor]; } }
y reemplaza esto.
<td style="font-size:10px;text-align:left;line-height:20px;" colspan="2">{$row["Contenedor1"]} - {$row["Contenedor2"]} - {$row["Contenedor3"]} - {$row["Contenedor4"]} - {$row["Contenedor5"]} - {$row["Contenedor6"]} - {$row["Contenedor7"]} - {$row["Contenedor8"]} - {$row["Contenedor9"]} - {$row["Contenedor10"]}</td>
Por esto otro.
<td style="font-size:10px;text-align:left;line-height:20px;" colspan="2">{$contenedores}</td>
lo puse entre { } la variable porque lo tenes asi, no se en que casos se usa eso, si te trae problemas sacala, es una variable y no un arreglo. en que casos se usa { ?
Espero que te sirva.
Saludos Votos: 2 - Link respuesta -
Fecha: 07-02-2019 17:51:56 Tienes algunos detalles con el código.
Prueba si te funciona lo siguiente:
//Get the info $idViaje = $_GET["id"]; $result = query(" SELECT Ucase(c.razonsocial) AS 'RazonSocial', Ucase(c.rfc) AS 'RFC', c.calle, c.colonia, Ucase(c.municipio) AS 'Municipio', Ucase(c.estado) AS 'Estado', c.cp, Ucase(v.cliente) AS 'Cliente', Ucase(tc.tipocontenedor) AS 'TipoContenedor', Ucase(v.contenedor1) AS 'Contenedor1', Ucase(v.contenedor2) AS 'Contenedor2', Ucase(v.contenedor3) AS 'Contenedor3', Ucase(v.contenedor4) AS 'Contenedor4', Ucase(v.contenedor5) AS 'Contenedor5', Ucase(v.contenedor6) AS 'Contenedor6', Ucase(v.contenedor7) AS 'Contenedor7', Ucase(v.contenedor8) AS 'Contenedor8', Ucase(v.contenedor9) AS 'Contenedor9', Ucase(v.contenedor10) AS 'Contenedor10', Ucase(v.referencia) AS 'Referencia', v.cartaporte, v.origen, v.destino, v.placas, v.operador, Ucase(v.tipooperacion) AS 'TipoOperacion', v.fechaalta, s.precio, s.limitmaxrespons, s.deduciblematerial, s.deduciblerobo FROM viajes v LEFT JOIN clientes c ON v.idcliente=c.idcliente LEFT JOIN servicios s ON (v.idtipocontenedor=s.idtipocontenedor AND v.idcliente=s.idcliente) LEFT JOIN tiposcontenedores tc ON tc.idtipocontenedor=v.idtipocontenedor WHERE v.idviaje=" . $idViaje ); $row = mysqli_fetch_array($result); // Set some content to print $arregloContenedores = []; for ($aux = 1; $aux <= 10; $aux++) { $arregloContenedores["Contenedor{$aux}"] = $row["Contenedor{$aux}"]; } $arregloContenedoresConValor = array_filter($arregloContenedores); $cant = count($arregloContenedoresConValor); $calle = ''; $razonSocial = htmlentities(strtoupper($row["RazonSocial"])); $origen = htmlentities(strtoupper($row["origen"])); $destino = htmlentities(strtoupper($row["destino"])); $operador = htmlentities(strtoupper($row["operador"])); $calle = htmlentities(strtoupper($row["calle"])); $municipio = htmlentities(strtoupper($row["Municipio"])); $estado = htmlentities(strtoupper($row["Estado"])); $cliente = htmlentities(strtoupper($row["Cliente"])); $refp = htmlentities(strtoupper($row["Referencia"])); $precio = (int)$row["precio"]; $subtotal = $precio * $cant; $iva = $subtotal * 0.16; $total = $subtotal * 1.16; $listaContenedores = implode(' - ', array_filter($arregloContenedoresConValor)); $html = <<<EOD <div style="text-align:center;"> <img src="img/logo.jpg" with="200" alt=""> <h5>Declaración de embarque</h5> </div> <table> <tr> <td style="font-size:10px;text-align:left;line-height:20px;">CONTENEDOR:</td> <td style="font-size:10px;text-align:left;line-height:20px;" colspan="2">{$listaContenedores}</td> <td style="font-size:10px;text-align:left;line-height:20px;">REFERENCIA:</td> <td style="font-size:10px;text-align:left;line-height:20px;" colspan="2">{$row["cartaPorte"]}</td> </tr> EOD;
Votos: 1 - Link respuesta -
Fecha: 08-02-2019 06:38:54 Muchas gracias por sus aportes, los 2 funcionaron ya quedo al 100, saludos Votos: 1 - Link respuesta
-
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión