2017-09-27 23 views
0

我不知道是否有人可以幫我用這段代碼?它被設計爲用查詢拉取數據,然後將所述數據放入圖像中。但是,我有一個問題,查詢的所有行都被打印出來,而不是每次換行。我相信這是我忽略的簡單東西,但任何幫助將不勝感激!同樣對不起,它正在建設中,看起來並不整齊!所以要清楚,我正在尋找它遍歷所有行,並將它們顯示在垂直列表中,但是,它當前將所有行都顯示出來,而不會有任何換行符!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); 

?> 
+0

我想這是因爲你使用同樣的座標每次 - (22,28)。你應該每次增加Y座標。多少,我不知道,但你可以嘗試16像素,並從那裏調整。 –

回答

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; 
} 
+0

輝煌,這已經成功了,謝謝你先生! – Samo

+0

@Samo很高興幫助。請好好接受答案。 =) –