LucianoCharles2017

tabelas_html_com_resultados_de_mais_tabelas_sql

Oct 5th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. $usuarios = ['nome1', 'nome2', 'nome3', 'nome4', 'nome5', 'nome6'];
  3. $maquinas = ['maquina1', 'maquina2', 'maquina3'];
  4.  
  5. $array = [
  6.     "usuarios" => $usuarios,
  7.     "maquinas" => $maquinas
  8. ];
  9. $t = null;
  10. /**
  11.  * PRECISO SABER QUAL DOS INDICES TEM MAIS VALUES
  12.  * ASSIM POSSO FAZER O FOR PELO MAIOR VALOR
  13.  */
  14. foreach ($array as $a) {
  15.     $t[] = count($a);
  16. }
  17. $total = max($t);
  18. ?>
  19.  
  20. <table class="table table-striped">
  21.     <thead>
  22.         <tr>
  23.             <th>Usuário</th>
  24.             <th>Maquina</th>
  25.         </tr>
  26.     </thead>
  27.     <tbody>
  28.         <?php
  29.         for ($p = 0; $p <= $total; $p++) {
  30.             echo "<tr>";
  31.             echo (isset($array['usuarios'][$p])) ? "<td>{$array['usuarios'][$p]}</td>" : "<td></td>";
  32.             echo (isset($array['maquinas'][$p])) ? "<td>{$array['maquinas'][$p]}</td>" : "<td></td>";
  33.             echo "</tr>";
  34.         }
  35.         ?>
  36.     </tbody>
  37. </table>
Advertisement
Add Comment
Please, Sign In to add comment