0

Image With Explanation

Inside this picture it explains it a little better, but basically In the html column, I need to have the players Avatar from an External URL Placed next to the users name. But I cant seem to get it to work I figured I would ask here because this community is rather helpful Here's the code:

<?php
$connection = mysql_connect('REMOVED', 'REMOVED', 'REMOVED'); 
mysql_select_db('stats');

$query = "SELECT * FROM stats"; 
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){   
echo "<tr><td><img src="'. "https://crafatar.com/avatars/" . $row['uuid'] .
 '">" . $row['name'] . "</td>";  
 echo "<td>" . $row['PLAYER_KILLS'] . "</td>";  
 echo "<td>" . $row['MOB_KILLS'] . "</td>";  
 echo "<td>" . $row['DEATHS'] . "</td>";  
 echo "<td>" . $row['DAMAGE_DEALT'] . "</td>";  
 echo "<td>" . $row['DAMAGE_TAKEN'] . "</td>";  
}



mysql_close(); 
?>
Thamilhan
  • 13,040
  • 5
  • 37
  • 59
  • If an answer solved your problem, consider accepting the answer. Here's how http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work then return here and do the same with the tick/checkmark till it turns green. This informs the community, a solution was found. Otherwise, others may think the question is still open and may want to post (more) answers. You'll earn points and others will be encouraged to help you. *Welcome to Stack!* – Jay Blanchard Jul 17 '17 at 17:39

2 Answers2

0

This should work:

echo "<tr><td><img src=\"https://crafatar.com/avatars/\"" . $row['uuid'] . ">" . $row['name'] . "</td>"; 

Use \" to escape "

McMuffinDK
  • 431
  • 3
  • 13
0

PHP will interpolate variables in brackets, so you can escape the quotes in the src tag and then enclose your variables in {}:

echo "<tr><td><img src=\"https://crafatar.com/avatars/{$row['uuid']}\">{$row['name']}</td>";

No concatenation required, the code is much cleaner. Here is an EXAMPLE.

The result is:

<tr><td><img src="https://crafatar.com/avatars/42">foo</td>

WARNING

You should stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy.

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
  • Thank you! I will definitely enclose them –  Jul 17 '17 at 17:42
  • 1
    my apology I'm new here I'm not exactly sure how everything works around here yet, thanks again! PS. Changed my answer –  Jul 17 '17 at 17:48