Guest User

Untitled

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php
  2. //Conexão e consulta ao Mysql
  3. mysql_connect('localhost','root','') or die(mysql_error());
  4. mysql_select_db('db_qualquer') or die(mysql_error());
  5. $qry = mysql_query("select * from turmas");
  6.  
  7. //Pegando os nomes dos campos
  8. $num_fields = mysql_num_fields($qry);//Obtém o número de campos do resultado
  9.  
  10. for($i = 0;$i<$num_fields; $i++){//Pega o nome dos campos
  11. $fields[] = mysql_field_name($qry,$i);
  12. }
  13.  
  14. //Montando o cabeçalho da tabela
  15. $table = '<table class="table table-hover table-inverse" style="margin-top:50;background-color: #37444a; color:lightgrey;"> <tr>';
  16.  
  17. for($i = 0;$i < $num_fields; $i++){
  18. $table .= '<th>'.$fields[$i].'</th>';
  19. }
  20.  
  21. //Montando o corpo da tabela
  22. $table .= '<tbody style="
  23. background-color: #86979e;
  24. color: #37444a;
  25. ">';
  26. while($r = mysql_fetch_array($qry)){
  27. $table .= '<tr>';
  28. for($i = 0;$i < $num_fields; $i++){
  29. $table .= '<td>'.$r[$fields[$i]].'</td>';
  30. }
  31.  
  32.  
  33. $table .= '<td><form action="inscricao.php" method="post">';
  34. $table .= '<input type="hidden" name="ID" value="'.$r['ID'].'">';
  35. $table .= '<input type="hidden" name="NOME" value="' . $r["NOME"] . '">';
  36. $table .= '<button class="btn btn-primary"><i class="glyphicon glyphicon-pencil"> Inscreva-se</i></button>';
  37. $table .= '</form></td>';
  38. }
  39.  
  40. //Finalizando a tabela
  41. $table .= '</tbody></table>';
  42.  
  43. //Imprimindo a tabela
  44. echo $table;
  45.  
  46. ?>
Add Comment
Please, Sign In to add comment