MySQL, PHP, HTML. Listing top 7 player kills
#1

I have a database for my server and I want to display the top 7 player kills. I'm not familiar at all with HTML or PHP really but I managed to find this code but it doesn't seem to work as I expected.

Код:
<html><head><title>Top Kills</title></head><body>
<?PHP
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = ' ';
 
$table = 'users';
 
IF (!MYSQL_CONNECT($db_host, $db_user, $db_pwd))
    DIE("Can't connect to database");
 
IF (!MYSQL_SELECT_DB($freemys2_mysql)) DIE("Can't select database");
 
// sending query
$result = "SELECT * FROM `users` ORDER BY `users`.`Kills` DESC LIMIT 7, 30 ";
IF (!$result) {
    DIE("Query to show fields from table failed");
}
 
$fields_num = MYSQL_NUM_FIELDS($result);
 
ECHO "<h1>Users: {$table}</h1>";
ECHO "<table border='1'><tr>";
// printing table headers
FOR($i=0; $i<$fields_num; $i++)
{
    $field = MYSQL_FETCH_FIELD($result);
    ECHO "<td>{$field->Kills}</td>";
}
ECHO "</tr>\n";
// printing table rows
WHILE($row = MYSQL_FETCH_ROW($result))
{
    ECHO "<tr>";
 
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    FOREACH($row AS $cell)
        ECHO "<td>$cell</td>";
 
    ECHO "</tr>\n";
}
MYSQL_FREE_RESULT($result);
 
?>
</body></html>
This outputs instead of a table, what am I doing wrong?
Код:
Users: {$table}"; ECHO ""; // printing table headers FOR($i=0; $i<$fields_num; $i++) { $field = MYSQL_FETCH_FIELD($result); ECHO ""; } ECHO "\n"; // printing table rows WHILE($row = MYSQL_FETCH_ROW($result)) { ECHO ""; // $row is array... foreach( .. ) puts every element // of $row to $cell variable FOREACH($row AS $cell) ECHO ""; ECHO "\n"; } MYSQL_FREE_RESULT($result); ?>
{$field->Kills}
$cell
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)