Web output
sanooj115 opened this issue ยท 3 comments
Hi!
Thanks for awesome plugin! Can you also publish source for your php code to display stats. That one what is on your SpigotMC page?
Br,
sanooj
The only thing missing from this is the database connection page. zStats creates 2 tables in the database, 'player' and 'stats'
The player table holds the player names and uuids, which is where the first SQL script comes in, it matches $_SESSION['username'] to the name in the player table and fetches the players UUID.
The UUID is used to retrieve the players stats and display them in a table.
// Init.php
define('DIRECT', TRUE);
$zStats = new zstats;
// Functions.php
class zstats
{
function getStats($odb)
{
$SQL = $odb -> prepare("SELECT * FROM player WHERE name = :user");
$SQL -> execute(array(":user" => $_SESSION['username']));
$userUUID = $SQL->fetchAll(); //Outputs User Plan ID
foreach($userUUID as $info)
{
$UUID = $info['uuid'];
}
$SQL = $odb -> prepare("SELECT * FROM stats WHERE uuid = :uuid"); // change $zodb to $odb for single table
$SQL -> execute(array(":uuid" => $UUID));
while ($row = $SQL->fetch(PDO::FETCH_ASSOC))
{
$zID = $row['id'];
$zStat = strtoupper(str_replace(" ONE CM", "", str_replace("_", " ", str_replace("z:", "", $row['stat'])))); //removes ONE CM, Underscores and z: from the outputs and capitalizes it all.
$zVal = $row['val'];
echo '<tr><td>'.$zStat.'</td><td>'.$zVal.'</td></tr>';
}
}
On the page you want it to display, you would set up a table with the callback for your function " $zStats->getStats($odb) "
<table class="table" style="text-align: center; width: 100%; height: 550px; display: inline-block; overflow: auto;">
<thead>
<tr>
<th>Raw Stat Identifier</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php echo $zStats->getStats($odb); // This is to call the function ?>
</tbody>
</table>