Horizontal line in a table in php

0

I want to put a horizontal line to separate data when viewing in a DGV in php, I use an 'echo' along with a '' to create the table, but I want to separate it by lines the records within the echo when creating the table, attach the code so far

$query = $db->prepare($sql); 
$query->execute(); 

echo  '<thead>
        <tr>    
          <th nowrap>Pregunta</th>
          <th nowrap>Respuesta</th>
          <th nowrap>Imagen</th>
          <th nowrap>Video</th>
          <th nowrap>Firma</th>
        </tr>
       </thead>

       <tbody>';
       foreach ($query as $valor) {
             echo  '<br />
            <tr>
              <td nowrap  style="width: 350px; text-align:center;">'. $valor[0] . '</td>
              <td nowrap  style="width: 120px; text-align:center;">'  . $valor[1] . '</td>
              <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$valor[2].'" rel="lightbox" >' . $valor[2] . '</a></td>                       
              <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$valor[3].'" rel="lightbox" width="150" height="150" >' . $valor[3] . '</a></td>
              <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$valor[4].'" rel="lightbox" >' . $valor[4] . '</a></td>  <br>        
            </tr> <br />';    
       }  
    
asked by Aruro deGyy 11.10.2016 в 19:37
source

4 answers

0

With <hr /> you can make a horizontal line, hopefully it will help! The complete example would be:

$query = $db->prepare($sql); 
$query->execute(); 

echo '
  <thead>
    <tr>    
      <th nowrap>Pregunta</th>
      <th nowrap>Respuesta</th>
      <th nowrap>Imagen</th>
      <th nowrap>Video</th>
      <th nowrap>Firma</th>
    </tr>
  </thead>
  <tbody>';
   foreach ($query as $valor) {
     echo  '
       <br />
       <tr>
         <td nowrap  style="width: 350px; text-align:center;">'. $valor[0] . '</td>
         <td nowrap  style="width: 120px; text-align:center;">'  . $valor[1] . '</td>
         <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$valor[2].'" rel="lightbox" >' . $valor[2] . '</a></td>                       
         <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$valor[3].'" rel="lightbox" width="150" height="150" >' . $valor[3] . '</a></td>
         <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$valor[4].'" rel="lightbox" >' . $valor[4] . '</a></td>  <br>        
       </tr>
       <br /> 
       <hr />';    
   }  

And if you want to separate each record you should put each class that has border: 1px solid black

    
answered by 11.10.2016 / 19:42
source
1

You can also use a

<tr>
    <td height="1" colspan="aqui tu número de columnas" style="border-bottom:1px solid #aquí tu color"></td>
</tr>

It is an additional cell with a lower edge. You can add the color you want

EDIT: If you want to draw the line every N iterations, just use:

$ counter = 1;

foreach ($query as $valor) {
    echo 'aqui los valores';
    if($valordecorte % $contador == 0){
        entonces inserto el separador
}


       } 
    
answered by 11.10.2016 в 19:44
1

You can do something like the following:

<style>
    .line td {
        border-bottom: 1px solid #000;
    }
</style>
<?php

$rows = array(
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
    array('Pregunta?', 'Respuesta!', 'imagen', 'video', 'firma'),
);

$table  = '';
$counter = 1; // Contador de registros agregados
$module = 5; // Cada cuantos registros vamos a "agregar" una linea horizontal
foreach ($rows as $row) {

    $class = (($counter % $module) === 0) ? 'line' : '';
    $table .=  '
        <tr class="'.$class.'">
          <td nowrap  style="width: 350px; text-align:center;">'. $row[0] . '</td>
          <td nowrap  style="width: 120px; text-align:center;">'  . $row[1] . '</td>
          <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$row[2].'" rel="lightbox" >' . $row[2] . '</a></td>                       
          <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$row[3].'" rel="lightbox" width="150" height="150" >' . $row[3] . '</a></td>
          <td nowrap  style="width: 200px; text-align:center;"><a target="_blank"  href="../img_uploaded/'.$row[4].'" rel="lightbox" >' . $row[4] . '</a></td>  <br>        
        </tr>';
    $counter++;
}
?>

<table>
    <thead>
        <tr>    
            <th nowrap>Pregunta</th>
            <th nowrap>Respuesta</th>
            <th nowrap>Imagen</th>
            <th nowrap>Video</th>
            <th nowrap>Firma</th>
        </tr>
    </thead>
    <tbody><?php echo $table; ?></tbody>
</table>

Here is the link to a demo: link

    
answered by 11.10.2016 в 20:54
0

The most practical thing is to put the border in tr and put the border-collapse in table , so that it covers all td , like this:

<table style="border-collapse: collapse">
.
.
.
<tr style="border-bottom:1px solid grey">
    <td>. . . . </td>
</tr>
    
answered by 11.10.2016 в 23:00