From 3cc4f6c3acc5e3d84975667759eefc2bb972d433 Mon Sep 17 00:00:00 2001 From: Thies Mueller Date: Sun, 10 Jan 2021 15:02:05 +0100 Subject: [PATCH] fancy the table --- adminarea_useradmin.php | 51 +++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/adminarea_useradmin.php b/adminarea_useradmin.php index 8904608..091085a 100644 --- a/adminarea_useradmin.php +++ b/adminarea_useradmin.php @@ -28,35 +28,42 @@ if($_SESSION['isadmin'] == 0) { } echo ''; -$conn = new mysqli($mysqlhost, $dbuser, $dbpass, $dbname); -// Run the query. -$result = $conn->query("SELECT * FROM users; LIMIT 10"); -// Get the result in to a more usable format. -$query = array(); -while($query[] = mysqli_fetch_assoc($result)); -array_pop($query); -// Output a dynamic table of the results with column headings. -echo ''; -echo ''; -foreach($query[0] as $key => $value) { - echo ''; +//create connection +$connection = mysqli_connect($mysqlhost, $dbuser, $dbpass, $dbname); + +//test if connection failed +if(mysqli_connect_errno()){ + die("connection failed: " + . mysqli_connect_error() + . " (" . mysqli_connect_errno() + . ")"); } -echo ''; -foreach($query as $row) { - echo ''; - foreach($row as $column) { - echo ''; + +//get results from database +$result = mysqli_query($connection,"SELECT * FROM users"); +$all_property = array(); //declare an array for saving property + +//showing property +echo '
'; - echo $key; - echo '
'; - echo $column; - echo '
+ '; //initialize table tag +while ($property = mysqli_fetch_field($result)) { + echo ''; //get field name for header + array_push($all_property, $property->name); //save those to array +} +echo ''; //end tr tag + +//showing all data +while ($row = mysqli_fetch_array($result)) { + echo ""; + foreach ($all_property as $item) { + echo ''; //get items using property value } echo ''; } -echo '
' . $property->name . '
' . $row[$item] . '
'; +echo ""; echo '

'; echo '';