PHP - imagestring重叠查询结果

时间:2017-09-27 10:31:39

标签: php

我想知道是否有人可以帮我处理这段代码?它被设计为使用查询提取数据,然后将所述数据放入图像中。但是,我遇到了一个问题,即查询的所有行都是相互打印出来的,而不是每次都在新行上打印出来!我确信这是我忽略的一些简单,但任何帮助将不胜感激!也很抱歉,它正在建设中,看起来并不整齐!所以要清楚,我正在寻找它遍历所有行,并将它们显示在一个垂直列表中,但是,它目前显示它们彼此之上没有任何换行!

<?php

$config = parse_ini_file('inc/config.ini'); 
$config1["image"] = "images/back.jpg"; // The default background image
// Try and connect to the database
$connection = mysqli_connect('127.0.0.1:3312',$config['username'],$config['password'],$config['dbname']);

// If connection was not successful, handle the error
if($connection === false) {
    // Handle error - notify administrator, log to a file, show an error screen, etc.
}

$result = mysqli_query($connection, "SELECT Name,PvPKills,PvEKills,NPCKills,HeliKills,APCKills,Deaths,Suicides,Status,TimePlayed FROM playerranksdb ORDER BY PvPKills DESC, PvEKills DESC, NPCKills DESC, HeliKills DESC, APCKills DESC LIMIT 10")
or die(mysqli_error()); 

// Make the image
        header ('Content-type: image/png');
        if(!isset($_GET['style'])) {
        $im = imagecreatefromjpeg($config1["image"]); } else {
        $im = imagecreatefromjpeg("image".$_GET['style'].".jpg");
        }

    // Various colors
        $textcolor = imagecolorallocate($im, 255, 255, 255);
        $border = imagecolorallocate($im, 135, 191, 231);
        $hpcolor = imagecolorallocate($im, 209, 48, 48);
        $mpcolor = imagecolorallocate($im, 204, 0, 255);
        $encolor = imagecolorallocate($im, 209, 184, 48);
        $oncolor = imagecolorallocate($im, 64, 225, 32);
        $offcolor = imagecolorallocate($im, 255, 80, 80);
        $rd = imagecolorallocate($im, 241, 241, 241);
        $rdblue = imagecolorallocate($im, 0, 180, 255);

while ($row = mysqli_fetch_assoc($result)){

    // Level and name
        imagestring($im, 3, 22, 28, "<Lv".$row['PvPKills']."> ".$row['Name'], $encolor);
    }       
    // Display image
        imagepng($im);
        imagedestroy($im);

mysqli_close($connection);

?>

1 个答案:

答案 0 :(得分:0)

扩展我的评论:

<?php
$y = 28;
while ($row = mysqli_fetch_assoc($result)) {
    // Level and name
    imagestring($im, 3, 22, $y, "<Lv".$row['PvPKills']."> ".$row['Name'], $encolor);
    $y += 16;
}