02.10.2017, 23:50
(
Last edited by vHero; 20/10/2017 at 08:50 AM.
Reason: Added Image Preview
)
Hello, I'm here to introduce a simple PHP/CSS/SQL script that will allow you to display your Servers MYSQL tables on your website. This script can display any SQL table information, whether it's your Servers Command Logs, or just anything that uses MYSQL Tables. You may use this on your website as a .php file, or a custom forum page. I manually edited this table with CSS.
- Note: Your Gamemode would need to run on MYSQL database for this to work on it.
- Note: Your Gamemode would need to run on MYSQL database for this to work on it.
Example of how the code can be modified:
Optional: You can remove the border-width:1px; and the border-color:grey or change the colors to suit your needs.
I'll try my best to provide support here when possible.
Optional: You can remove the border-width:1px; and the border-color:grey or change the colors to suit your needs.
PHP Code:
<?php
//Step1
$db = mysqli_connect('DATABASE_HOST','DATABASE_USER','DATABASE_PASSWORD','DATABASE_NAME')
or die('Error connecting to MySQL server.');
?>
<?php
//Step2
$query = "SELECT * FROM `TABLE_NAME` ORDER BY `COLUMN_NAME`.`COLUMN_NAME` DESC";
mysqli_query($db, $query) or die('Error querying database.');
//Step3
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
//Step4
echo "<center><style type=\"text/css\">";
echo ".tg {border-collapse:collapse;border-spacing:0;border-color:#fff;}";
echo ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:17px 10px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:grey;color:#fff;background-color:black;}";
echo ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:grey;color:#fff;background-color:black;}";
echo ".tg .tg-baqh{text-align:center;vertical-align:top}";
echo "</center></style>
<table class=\"tg\">";
//Step5 - opening table tag
echo '<th class=\"tg-baqh\"><center>Column_Name1</center></th><th class=\"tg-baqh\"><center>Column_Name2</center></th></th><th class=\"tg-baqh\"><center>Column_Name3</center></th><th class=\"tg-baqh\"><center>Column_Name4</center></th>';
//table headers
while ($row = mysqli_fetch_array($result)) {
// we are running a while loop to print all the rows in a table
echo'<tr>'; // printing table row
//Step6
echo '<td><center>' . $row['Column_Name1'] . '</center></td><td><center>' . $row['Column_Name2'] . '</center></td><td><center>' . $row['Column_Name3'] . '</center></td><td><center>' . $row['Column_Name4'] .'</center></td>';
// we are looping all data to be printed till last row in the table
echo'</tr>'; // closing table row
}
echo '</table>'; //closing table tag
?>