gpt4 book ai didi

php - 4个div中列的Mysql + php值

转载 作者:行者123 更新时间:2023-11-30 22:30:01 25 4
gpt4 key购买 nike

您好,我正在尝试使它正常工作,但无法正常工作。

所以基本上我从 2 个表中获取数据。

  • 1st= 玩家信息
  • 2nd= playerstats

  • 我想从玩家信息中获取 BankMoney 列的总值

  • 我想从 playerstats 获得 PlayerKills 、 DeathCount 、 AIKills 的总值

并让他们在那里展示。

columns total here

这是我的代码

<?php
$dbname = '';
$dbuser = '';
$dbpass = '';
$dbhost = ''; // localhost should suffice
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or exit(mysql_error());
mysql_select_db($dbname, $conn) or exit(mysql_error());

$loopResult = ''; // leave blank to start var for loop
$result = mysql_query("select * from playerstats,playerinfo limit 0,10") or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
$loopResult = '
<div class="container">

<div class="section-header">
<h2 class="section-title wow fadeInDown">Tous les stats</h2>
<p class="wow fadeInDown">Voici la totaliter des stats du serveur wasteland <b>En développement</b></p>
</div>

<div class="row text-center">
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="wow fadeInUp" data-wow-duration="400ms" data-wow-delay="0ms">
<div class="business-stats" data-digit="'.$row['AIKills'].'" data-duration="1000"></div>
<strong>Joueurs</strong>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="wow fadeInUp" data-wow-duration="400ms" data-wow-delay="100ms">
<div class="business-stats" data-digit="'.$row['PlayerKills'].'" data-duration="1000"></div>
<strong>Victimes</strong>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="wow fadeInUp" data-wow-duration="400ms" data-wow-delay="200ms">
<div class="business-stats" data-digit="'.$row['BankMoney'].'" data-duration="1000"></div>
<strong>Argent totale</strong>
</div>
</div>
<div class="col-md-3 col-sm-6 col-xs-12">
<div class="wow fadeInUp" data-wow-duration="400ms" data-wow-delay="300ms">
<div class="business-stats" data-digit="'.$row['DeathCount'].'" data-duration="1000"></div>
<strong>Deces</strong>
</div>
</div>
</div>
</div>
';
}
echo $loopResult;
?>

如果有人可以帮助我,我将不胜感激。

谢谢

表模式

-- -----------------------------------------------------
-- Table `PlayerStats`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PlayerStats`
(
`PlayerUID` VARCHAR(32) NOT NULL,
`LastModified` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`PlayerKills` INT UNSIGNED NOT NULL DEFAULT 0,
`AIKills` INT UNSIGNED NOT NULL DEFAULT 0,
`TeamKills` INT UNSIGNED NOT NULL DEFAULT 0,
`DeathCount` INT UNSIGNED NOT NULL DEFAULT 0,
`ReviveCount` INT UNSIGNED NOT NULL DEFAULT 0,
`CaptureCount` INT UNSIGNED NOT NULL DEFAULT 0,
UNIQUE INDEX `idx_PlayerStats_uniquePlayer` (`PlayerUID` ASC),
CONSTRAINT `fk_PlayerStats_PlayerInfo`
FOREIGN KEY (`PlayerUID`)
REFERENCES `PlayerInfo` (`UID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `PlayerInfo`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `PlayerInfo`
(
`UID` VARCHAR(32) NOT NULL,
`CreationDate` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`Name` VARCHAR(256) CHARACTER SET 'utf8' NULL,
`LastSide` VARCHAR(32) NULL,
`BankMoney` FLOAT NOT NULL DEFAULT 0,
`BattlEyeGUID` VARCHAR(32) NULL,
PRIMARY KEY (`UID`))
ENGINE = InnoDB;

最佳答案

我认为您需要使用“加入”来为单个用户获取两个表的结果。

查询应该是这样的

sql="select *, (PlayerKills+AIKills+TeamKills) as total_kill from playerinfo left join playerstats on playerstats.PlayerUID =  playerinfo.UID limit 0,10"

total_kill 将具有所有三个值的总和。

有关左连接的更多详细信息,请查看此 http://www.mysqltutorial.org/mysql-left-join.aspx

关于php - 4个div中列的Mysql + php值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34119108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com