我已将统计信息存储在数据库中。我希望我们 MediaWiki 中的用户仅查看与其用户名相关的统计信息。我在下面尝试过,但它只给了我一个空白页(没有错误)。我的猜测是它没有从会话中获取用户名。我应该如何做到这一点?
<?php
$dbtype = "mysql";
$dbhost = "localhost";
$dbname = "test";
$dbuser = "username";
$dbpassword = "passw0rd";
$conn = mysql_connect($dbhost, $dbuser, $dbpassword);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$wgHooks['UserLoginComplete'][] = 'test::onUserLoginComplete';
class test
{
public static function UserLoginComplete( $user, $password, &$retval, &$msg ) {
$dbr = wfGetDB( DB_SLAVE );
$row = $dbr->selectRow(
'coaching', // $Table
'Name', // $vars (column of the table)
array( 'Name' => $user ), // $Conitions
__METHOD__ // $fname = 'Database::select'
);
mysql_select_db($dbname, $conn);
echo '<table border="0" border-color="#CCCCCC" bgcolor="#FFFFFF"><thead><tr><td><b>ID</b></td><td><b>Namn</b></td><td><b>Datum</b></td><td><b>Score</b></td></tr></thead><tbody>';
$query = "SELECT ID, Name, Date, Score FROM coaching WHERE Name = $user";
$result = mysql_query($query) or die(mysql_error());
$color="1";
while($row = mysql_fetch_array($result)){
if($color==1){
echo '<tr bgcolor="#D0D0D0">';
$color="2";
} else {
echo '<tr bgcolor="#E0E0E0">';
$color="1";
}
echo '<td>'.$row['ID'].'</td><td>'.$row['Name'].'</td><td>'.$row['Date'].'</td><td>'.$row['Score'].'</td></tr>';
}
?>