fancy the table

This commit is contained in:
Thies Mueller 2021-01-10 15:02:05 +01:00
parent e3ab5183cb
commit 3cc4f6c3ac

View File

@ -28,35 +28,42 @@ if($_SESSION['isadmin'] == 0) {
} }
echo '<div class="alert alert-danger" role="alert">heres the admin world</div>'; echo '<div class="alert alert-danger" role="alert">heres the admin world</div>';
$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. //create connection
echo '<table border="1">'; $connection = mysqli_connect($mysqlhost, $dbuser, $dbpass, $dbname);
echo '<tr>';
foreach($query[0] as $key => $value) { //test if connection failed
echo '<td>'; if(mysqli_connect_errno()){
echo $key; die("connection failed: "
echo '</td>'; . mysqli_connect_error()
. " (" . mysqli_connect_errno()
. ")");
} }
echo '</tr>';
foreach($query as $row) { //get results from database
echo '<tr>'; $result = mysqli_query($connection,"SELECT * FROM users");
foreach($row as $column) { $all_property = array(); //declare an array for saving property
echo '<td>';
echo $column; //showing property
echo '</td>'; echo '<table class="table table-striped">
<tr class="data-heading">'; //initialize table tag
while ($property = mysqli_fetch_field($result)) {
echo '<td>' . $property->name . '</td>'; //get field name for header
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag
//showing all data
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
foreach ($all_property as $item) {
echo '<td>' . $row[$item] . '</td>'; //get items using property value
} }
echo '</tr>'; echo '</tr>';
} }
echo '</table>'; echo "</table>";
echo '<br /> <br />'; echo '<br /> <br />';
echo '<a href="adminarea.php"><button class="btn btn-info">Back</button></a>'; echo '<a href="adminarea.php"><button class="btn btn-info">Back</button></a>';