Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] NO me imprime dentro de una tabla

Estas en el tema de NO me imprime dentro de una tabla en el foro de PHP en Foros del Web. Hola creado una nueva funcion y necesito que la imprima dentro de una tabla pero me la deja fuera. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código PHP: Ver original ...
  #1 (permalink)  
Antiguo 12/11/2015, 05:51
 
Fecha de Ingreso: febrero-2011
Ubicación: Barcelona
Mensajes: 195
Antigüedad: 13 años, 2 meses
Puntos: 1
NO me imprime dentro de una tabla

Hola
creado una nueva funcion y necesito que la imprima dentro de una tabla pero me la deja fuera.

Código PHP:
Ver original
  1. echo '<table class="table  table-bordered table-striped datatable"  id="table-2">';
  2. echo    '<thead>';
  3. echo        '<tr class="success" >';
  4. echo            '<th>Contrato</th>';
  5. echo            '<th>Cliente</th>';
  6. echo            '<th>Matricula Tractora</th>';
  7. echo            '<th>DNI PASAPORTE</th>';
  8. echo            '<th>Matricula Remolque</th>';
  9. echo            '<th>Nombre</th>';
  10. echo            '<th>Estado</th>';  
  11. echo        '</tr>';
  12. echo    '</thead>';
  13. function muestraEstado($estado)
  14. {
  15.     if($estado === 'Confirmada') {
  16.         echo '<button type="button" class="btn btn-success">
  17.            <i class="entypo-check"></i>
  18.        </button>';
  19.     } else {
  20.         echo $estado;
  21.     }
  22. }
  23.  
  24. if (is_array($distribuciones)) {
  25.  foreach($distribuciones as $distrib) {
  26.  
  27.  echo ' <tbody>
  28.        <tr>
  29.            <td>'.$distrib->Contrato.'</td>
  30.            <td>'.$distrib->Cliente.'</td>
  31.            <td>'.$distrib->Matricula_tractora.'</td>
  32.            <td>'.$distrib->DNI_conductor.'</td>
  33.            <td>'.$distrib->Matricula_remolque.'</td>
  34.            <td>'.$distrib->Nombre_conductor.'</td>
  35.            <td>'.muestraEstado($distrib->Estado).'</td>  <---------------- esto deberia imprimrlo en la tabla
  36.            </tr>';        
  37.  
  38.   }    
  39. }
  40. echo '</table>';

ejemplo:
[IMG]
subir foto[/IMG]


como podeis comprobar lo hace fuera

alguien sabe porque?
  #2 (permalink)  
Antiguo 12/11/2015, 06:12
 
Fecha de Ingreso: julio-2015
Mensajes: 14
Antigüedad: 8 años, 9 meses
Puntos: 0
Respuesta: NO me imprime dentro de una tabla

el tbody no esta cerrado, no creo que sea eso pero fijate
  #3 (permalink)  
Antiguo 12/11/2015, 06:24
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 10 meses
Puntos: 263
Respuesta: NO me imprime dentro de una tabla

el tbody es el problema, al menos hasta donde se ver, prueba asi:
Código PHP:
Ver original
  1. echo '<table class="table  table-bordered table-striped datatable"  id="table-2">';
  2. echo    '<thead>';
  3. echo        '<tr class="success" >';
  4. echo            '<th>Contrato</th>';
  5. echo            '<th>Cliente</th>';
  6. echo            '<th>Matricula Tractora</th>';
  7. echo            '<th>DNI PASAPORTE</th>';
  8. echo            '<th>Matricula Remolque</th>';
  9. echo            '<th>Nombre</th>';
  10. echo            '<th>Estado</th>';  
  11. echo        '</tr>';
  12. echo    '</thead><tbody>';//AQUI INICIAMOS EL BODY
  13. function muestraEstado($estado)
  14. {
  15.     if($estado === 'Confirmada') {
  16.         echo '<button type="button" class="btn btn-success">
  17.            <i class="entypo-check"></i>
  18.        </button>';
  19.     } else {
  20.         echo $estado;
  21.     }
  22. }
  23.  
  24. if (is_array($distribuciones)) {
  25.  foreach($distribuciones as $distrib) {
  26.  
  27.  echo '
  28.        <tr>
  29.            <td>'.$distrib->Contrato.'</td>
  30.            <td>'.$distrib->Cliente.'</td>
  31.            <td>'.$distrib->Matricula_tractora.'</td>
  32.            <td>'.$distrib->DNI_conductor.'</td>
  33.            <td>'.$distrib->Matricula_remolque.'</td>
  34.            <td>'.$distrib->Nombre_conductor.'</td>
  35.            <td>'.muestraEstado($distrib->Estado).'</td>  <---------------- esto deberia imprimrlo en la tabla
  36.            </tr>';        
  37.  
  38.   }    
  39. }
  40. echo '</tbody></table>';//AQUI CERRAMOS EL BODY
__________________
[email protected]
HITCEL
  #4 (permalink)  
Antiguo 12/11/2015, 06:24
Avatar de jpint  
Fecha de Ingreso: junio-2012
Ubicación: Ciudad Real - España
Mensajes: 97
Antigüedad: 11 años, 10 meses
Puntos: 12
Respuesta: NO me imprime dentro de una tabla

El <tbody> debe estar fuera del bucle.
Código PHP:
if (is_array($distribuciones)) { 

    echo 
' <tbody>';

     foreach(
$distribuciones as $distrib) {
            echo 
'<tr>
                <td>'
.$distrib->Contrato.'</td>
                <td>'
.$distrib->Cliente.'</td>
                <td>'
.$distrib->Matricula_tractora.'</td>
                <td>'
.$distrib->DNI_conductor.'</td>
                <td>'
.$distrib->Matricula_remolque.'</td>
                <td>'
.$distrib->Nombre_conductor.'</td>
                <td>'
.muestraEstado($distrib->Estado).'</td> 
            </tr>'
;        
     
      }  

    echo 
'</tbody>';


  #5 (permalink)  
Antiguo 12/11/2015, 10:20
 
Fecha de Ingreso: febrero-2011
Ubicación: Barcelona
Mensajes: 195
Antigüedad: 13 años, 2 meses
Puntos: 1
Respuesta: NO me imprime dentro de una tabla

Tenias razon los dos pero no del todo, por al poner "muestraEstado($estado) entre los puntos me lo quitaba fuera de la tabla , y aunque cerraba el body , me lo sacaba fuera de la tabla.

asi que al fin intente otra cosa:
[HIGHLIGHT="PHP"]echo '<table class="table table-bordered table-striped datatable" id="table-2">';
echo '<thead>';
echo '<tr class="success" >';
echo '<th>Contrato</th>';
echo '<th>Cliente</th>';
echo '<th>Matricula Tractora</th>';
echo '<th>DNI PASAPORTE</th>';
echo '<th>Matricula Remolque</th>';
echo '<th>Nombre</th>';
echo '<th>Estado</th>';
echo '</tr>';
echo '</thead>';
function muestraEstado($estado)
{
if($estado === 'Confirmada') {
echo '<td><button type="button" class="btn btn-success">
<i class="entypo-check"></i>
</button></td>';
} else {
echo $estado;
}
}


if (is_array($distribuciones)) {
foreach($distribuciones as $distrib) {


echo ' <tbody>
<tr>

<td>'.$distrib->Contrato.'</td>
<td>'.$distrib->Cliente.'</td>
<td>'.$distrib->Matricula_tractora.'</td>
<td>'.$distrib->DNI_conductor.'</td>
<td>'.$distrib->Matricula_remolque.'</td>
<td>'.$distrib->Nombre_conductor.'</td>';
muestraEstado($estado);
echo '</tr>
</tbody>';
}

}




DE todas las maneras Gracias por la ayuda

Última edición por javierconesa23; 24/11/2015 a las 13:37

Etiquetas: imprime, tabla
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




La zona horaria es GMT -6. Ahora son las 23:57.