سؤال

So I have aquired a PHP Script which checks and grabs server information from the servers of the popular game 'Minecraft'. Everything in the script seems to work perfect but I get one error,

Notice: Undefined variable: users in C:\xampp\htdocs\web-root\UNNAMED\share\site\fol\avatarquery.php on line 74

I have no idea why this is happening (I am relatively new to PHP), here's the PHP code;

            <?php
            //Take the username values from the array & grab the avatars from Minotar.              
            foreach($array_list as $key => $value){$users .= "<a data-placement=\"top\" rel=\"tooltip\" style=\"display: inline-block;\" title=\"".$value."\">
            <img src=\"https://minotar.net/avatar/".$value."/50\" size=\"40\" width=\"40\" height=\"40\" style=\"width: 40px; height: 40px; margin-bottom: 5px; margin-right: 5px; border-radius: 3px;\"/></a>";}
            //Display the avatars only when there are players online.
            if($data_general['players']['online'] > 0) {
                print_r($users);
                }
            //If no avatars can be shown, display an error.
            else { 
                echo "<div class=\"alert\"> There are no players online at the moment!</div>";
                }               
            ?>

Any and all help would be greatly appreciated! Thank you!

Oh and the code <img src=" is line 74.

هل كانت مفيدة؟

المحلول

thats a notice error thats warning you about concatenating to a variable that doesn't yet exist.

add this line above your foreach to remove it:

    $users = "";
    foreach($array_list as $key => $value.....
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top