Advertisement
Guest User

Untitled

a guest
Jun 17th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <?php
  2. $servername ="localhost";
  3. $username="root";
  4. $password="";
  5. $dbname="casaldogrilo";
  6. //cria conexão
  7. $conn = new mysqli($servername, $username, $password, $dbname);
  8. // verifica conexão
  9. if ($conn->connect_error) {
  10. die("Connection failed: " . $conn->connect_error);
  11. }
  12. $sql = "SELECT * FROM juniores order by Nome ASC";
  13. $result = $conn->query($sql);
  14. if ($result->num_rows > 0) {
  15. echo "<table style='width:100%' height='100%'>
  16. <tr>
  17. <th>Nome</th>
  18. <th>Data_Nasc</th>
  19. <th>Idade</th>
  20. <th>Nacionalidade</th>
  21. </tr>";
  22. // output data of each row
  23. while($row = $result->fetch_assoc()) {
  24. echo "<tr>
  25. <td align='center'>".$row["Nome"]."</td>
  26. <td align='center'>".$row["Data_Nasc"]."</td>
  27. <td align='center'>".$row["Idade"]."</td>
  28. <td align='center'>".$row["Nacionalidade"]."</td>
  29. </tr>";
  30. }
  31. echo "</table>";
  32. } else {
  33. echo "0 results";
  34. }
  35. $conn->close();
  36. ?>
  37.  
  38. if ($result->num_rows > 0) {
  39. echo "<table style='width:100%' height='100%'>
  40. <tr>
  41. <th>Nome</th>
  42. <th>Data_Nasc</th>
  43. <th>Idade</th>
  44. <th>Nacionalidade</th>
  45. </tr>";
  46. // output data of each row
  47. while($row = $result->fetch_assoc()) {
  48. echo '<tr>
  49. <td align="center"><a href="jogador.php?id=' .$row["id"]. '">' .$row["Nome"]. '</a></td>
  50. <td align="center">' .$row["Data_Nasc"]. '</td>
  51. <td align="center">' .$row["Idade"]. '</td>
  52. <td align="center">' .$row["Nacionalidade"]. '</td>
  53. </tr>';
  54. }
  55. echo "</table>";
  56.  
  57. <?php
  58. if(!isset($_GET['id'])) {
  59. die('Não existe um id definido');
  60. }
  61. if(!is_numeric($_GET['id'])) {
  62. die('ID inválido');
  63. }
  64. else {
  65. $servername = "localhost"; $username = "root"; $password = ""; $dbname = "casaldogrilo"; // cria conexão
  66. $conn = new mysqli($servername, $username, $password, $dbname); // verifica conexão
  67. if ($conn->connect_error) {
  68. die("Connection failed: " . $conn->connect_error);
  69. }
  70. $sql = "SELECT * FROM juniores WHERE id=" .$_GET['id'];
  71. $result = $conn->query($sql);
  72. if ($result->num_rows > 0) {
  73. $jogador = $result->fetch_assoc();
  74. echo 'Nome: ' .$jogador['Nome'];
  75. echo 'Data Nascimento: ' .$jogador['Data_Nasc'];
  76. echo 'Idade: ' .$jogador['Idade'];
  77. echo 'Nacionalidade: ' .$jogador['Nacionalidade'];
  78. }
  79. else {
  80. echo 'Jogador não encontrado';
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement