Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function connect($host, $user, $pass, $db)
- {
- $mysqli = new Mysqli($host, $user, $pass, $db);
- return $mysqli;
- }
- function connect_close($conn)
- {
- return $conn->close();
- }
- function getAll($conn, $tbl)
- {
- $all = array();
- $query = "SELECT * FROM $tbl";
- if ($res = $conn->query($query))
- {
- while ($row = $res->fetch_assoc())
- {
- array_push($all, $row);
- }
- }
- return $all;
- }
- function outputTable($all, $cN)
- {
- $output = "<table class='" . $cN . "'><thead><tr>";
- foreach ($all[0] as $k => $v)
- {
- $output .= "<th>$k</th>";
- }
- $output .= "</tr></thead><tbody>";
- foreach ($all as $i => $row)
- {
- $output .= "<tr>";
- foreach ($row as $i => $value)
- {
- $output .= "<td>$value</td>";
- }
- $output .= "</tr>";
- }
- $output .= "</tbody></table>";
- return $output;
- }
- // Run with
- include_once "functions.php";
- $host = "localhost";
- $user = "root";
- $pass = "";
- $db = "chat";
- $tbl = "tl_user";
- $c = connect($host, $user, $pass, $db);
- $all = getAll($c, $tbl);
- echo outputTable($all, "myTable");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement