1

Hello I am trying to make this thing work but cant get it working.

So basically I have 2 tables I am fetching data from.

  • 1st= playerinfo
  • 2nd= playerstats

  • From playerinfo I want to get the total value of column BankMoney

  • From playerstats I want to get the total value of PlayerKills , DeathCount , AIKills

And make them show there.

columns total here

Here is my code

<?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;
?>

If someone could assist me with this I would appreciate it.

Thank you

Table shemas

-- -----------------------------------------------------
-- 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;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
t0ks1ck514
  • 23
  • 6
  • And what is your question? What error message do you receive or unexpected behaviour do you encounter? – Shadow Dec 06 '15 at 15:39
  • I do not get any errors, I just dont know how to get those data , I want the total of colums BankMoney , PlayerKills, AIKills, DeathCount but each separate – t0ks1ck514 Dec 06 '15 at 15:42
  • You are not able to write the sql for this data?, show your tables schema please. – ScaisEdge Dec 06 '15 at 15:43
  • Alright , I edited my post with the shemas – t0ks1ck514 Dec 06 '15 at 15:47
  • you know you can use html stuff to loop html content – Nicolas Manzini Dec 06 '15 at 17:41
  • 1
    Please refactor your code to use the [MySQLi](http://php.net/mysqli) or [PDO](http://php.net/manual/en/ref.pdo-mysql.php) extension instead. The MySQL extension [has been deprecated](http://php.net/manual/en/intro.mysql.php) since 2013 and has been dropped in PHP7 that was released earlier this week. So this code will not work on PHP7. Also see [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – Oldskool Dec 06 '15 at 18:03

3 Answers3

0

You seem not to be showing the values in the html, only in the class - for example:

       <div class="business-stats" data-digit="'.$row['PlayerKills'].'" data-duration="1000">
       <strong>Victimes</strong>

Should be

       <div class="business-stats" data-digit="'.$row['PlayerKills'].'" data-duration="1000">'.$row['PlayerKills'].'</div>
       <strong>Victimes</strong>
       </div>
     </div>  
Steve
  • 808
  • 1
  • 9
  • 14
0

I think you need to use "Join" to get result for both tables for single user.

The query should be like

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

total_kill will have the total of all three values.

for more details of left join please check this http://www.mysqltutorial.org/mysql-left-join.aspx

Manish Shukla
  • 1,355
  • 2
  • 8
  • 21
  • got it working it shows data. but what i actualy want is show the total of the rows. lets say PlayerKill as 3 rows , row1=7kill row2= 3 kill and row3 = 4 kills it would show 14 kills – t0ks1ck514 Dec 06 '15 at 17:47
  • if you want to add values of three columns then check my updated answer. and if you want to sum rows value then you can use sum function of my sql. – Manish Shukla Dec 06 '15 at 17:54
0

Keep it simple, after grabbing the data from the db, pass it to a loop, in which you make sums in correspondent variables, after that just show the sums, for example:

Foreach ($arr as $row ){
  $sum_kills += $row ['kills'];
  $sum_fights += $row ['FIGHT']:
}
Yazid Erman
  • 1,166
  • 1
  • 13
  • 24