Advertisement
humpda

Display_Data_from_SQLTable

Jul 30th, 2024
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2. $server = "localhost";
  3. $username = "testuser2024";
  4. $password = "testuser";
  5. $db = "testuser2024_TestDbase";
  6.  
  7. $conn = mysqli_connect ($server, $username, $password, $db);
  8.  
  9. // I can remove this check...it serves no purpose now.
  10. //if (!$conn) {
  11. //    die("connection failed: " . mysqli_connect_error());
  12. //    
  13. //}
  14. //echo("connected successfully homieG");
  15.  
  16.  
  17.  
  18. $query = mysqli_query($conn, "Select Student_ID, Surname, Age from Student_details") or die(mysql_error($conn));
  19.  
  20.  
  21. echo("<table border=\"1\">"); //this puts a border around the data using line thickness of 1
  22.  
  23. echo("<tr> <td>ID</td> <td>Surname</td> <td>Age</td> </tr>"); //this put column headings in <td> = cell
  24.  
  25.  
  26.  
  27. while ($row = mysqli_fetch_array($query)) {
  28.    
  29.     printf("<tr> <td>%s</td> <td>%s</td>  <td>%s</td> </tr>", $row['Student_ID'], $row['Surname'], $row['Age']);
  30.    
  31.     //%s essentially means grab the value from the SQL table and insert it here.  Try leaving the %s out and see what happens :)
  32. }
  33.  
  34.  
  35. echo("</table>");
  36.  
  37. mysqli_close($conn);
  38.  
  39. ?>
  40.  
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement