我目前正在构建排行榜(https://mgo.io/mgo3/leaderboard.php),而且我在手动接受数据方面遇到了问题。我希望它从我的MySQL数据库中获取数据,并允许我手动输入并输入数据,它也将显示。它目前抓住了部族db的id和部族名称。
如何让它读取我从两个新的'胜利中输入的数据?和'损失'我在db中添加的列已经从?
中获取数据继承我的代码:
<?php
include_once "Log.class.php";
include_once "dbcon.php";
function getLeaders() {
global $dbh;
date_default_timezone_set('UTC');
$res = array();
$stmt = $dbh->prepare("SELECT id, name FROM clans ORDER BY id ASC");
$stmt->execute();
while ($row = $stmt->fetch()) {
$clan_id = (int) $row['id'];
$clan_name = $row['name'];
$res[$clan_id] = array();
$res[$clan_id]['name'] = $clan_name;
$res[$clan_id]['rank'] = 0;
$res[$clan_id]['cp'] = 0;
$res[$clan_id]['win'] = 0;
$res[$clan_id]['loss'] = 0;
?>
答案 0 :(得分:1)
只需将字段添加到SELECT语句中,并将检索到的值分配给适当的变量:
// Add wins & losses here:
$stmt = $dbh->prepare("SELECT id, name, wins, losses
FROM clans ORDER BY id ASC");
$stmt->execute();
while ($row = $stmt->fetch()) {
$clan_id = (int) $row['id'];
$clan_name = $row['name'];
$res[$clan_id] = array();
$res[$clan_id]['name'] = $clan_name;
$res[$clan_id]['rank'] = 0;
$res[$clan_id]['cp'] = 0;
$res[$clan_id]['win'] = $row['wins']; // <<<< and here...
$res[$clan_id]['loss'] = $row['losses']; // <<<<