Advertisement
Guest User

Untitled

a guest
Jun 9th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function connect($host, $user, $pass, $db)
  2. {
  3. $mysqli = new Mysqli($host, $user, $pass, $db);
  4. return $mysqli;
  5. }
  6.  
  7. function connect_close($conn)
  8. {
  9. return $conn->close();
  10. }
  11.  
  12. function getAll($conn, $tbl)
  13. {
  14. $all = array();
  15. $query = "SELECT * FROM $tbl";
  16.  
  17. if ($res = $conn->query($query))
  18. {
  19. while ($row = $res->fetch_assoc())
  20. {
  21. array_push($all, $row);
  22. }
  23. }
  24.  
  25. return $all;
  26. }
  27.  
  28. function outputTable($all, $cN)
  29. {
  30. $output = "<table class='" . $cN . "'><thead><tr>";
  31. foreach ($all[0] as $k => $v)
  32. {
  33. $output .= "<th>$k</th>";
  34. }
  35. $output .= "</tr></thead><tbody>";
  36.  
  37. foreach ($all as $i => $row)
  38. {
  39. $output .= "<tr>";
  40.  
  41. foreach ($row as $i => $value)
  42. {
  43. $output .= "<td>$value</td>";
  44. }
  45. $output .= "</tr>";
  46. }
  47.  
  48. $output .= "</tbody></table>";
  49.  
  50. return $output;
  51. }
  52.  
  53. // Run with
  54.  
  55. include_once "functions.php";
  56.  
  57. $host = "localhost";
  58. $user = "root";
  59. $pass = "";
  60. $db = "chat";
  61. $tbl = "tl_user";
  62.  
  63. $c = connect($host, $user, $pass, $db);
  64. $all = getAll($c, $tbl);
  65.  
  66. echo outputTable($all, "myTable");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement