2017-12-31 105 views
0

Hallo Ich habe eine einfache Benutzerliste durch die Ergebnisse in der Datenbank erstellt, und ich habe zwei Probleme mit ihm ..Wie erstelle ich eine Benutzerliste richtig?

ich auf meiner Liste wie folgt erhalten:

[UserOne, ...] [UserTwo, ...]

Aber ich brauche so zu erhalten:

[UserOne], [UserTwo] ...

und von den drei Punkten i die Ergebnisse auf 20 beispielsweise begrenzen müssen und Stellen Sie dann die drei Punkte ein.

Image: https://prntscr.com/huj1e4

meinen Code ein:

$PageSqla = "SELECT * FROM `table` WHERE status = 'online' ORDER BY nome ASC "; 
       $jogadoresonline = mysqli_query($connectionae, $PageSqla); 
       echo "<div class='bundinhabonita'>Players online - (".mysqli_num_rows($jogadoresonline).")</div>"; 


       if(mysqli_fetch_array($jogadoresonline)){ 
        foreach($jogadoresonline as $merda){ 

           if($merda['grupo'] == "CEO"){ 
        $mimimi = "<span style='font-weight: bold;color: #D9A334;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "Manager"){ 
        $mimimi = "<span style='font-weight: bold;color: #aa0000;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "Admin"){ 
        $mimimi = "<span style='font-weight: bold;color: #ff5555;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "Moderator"){ 
        $mimimi = "<span style='font-weight: bold;color: #00aa00;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "Helper"){ 
        $mimimi = "<span style='font-weight: bold;color: #E3D628;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "Builder"){ 
        $mimimi = "<span style='font-weight: bold;color: #3F3FFE;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "YouTuber"){ 
        $mimimi = "<span style='font-weight: bold;color: #ff5555; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "MVP+"){ 
        $mimimi = "<span style='font-weight: bold;color: #3ffe3f; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "MVP"){ 
        $mimimi = "<span style='font-weight: bold;color: #00aa00; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "VIP+"){ 
        $mimimi = "<span style='font-weight: bold;color: #be00be; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "VIP"){ 
        $mimimi = "<span style='font-weight: bold;color: #00bebe; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }elseif($merda['grupo'] == "Member"){ 
        $mimimi = "<span style='font-weight: bold;color: #bebebe; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
         }    



        echo $mimimi."<span style='color: black;'>...</span>"; 


        } 


       }else{ 
        echo "<div style='color: grey;'>None is online.</div>"; 
       } 
+0

echo $ mimimi. " ..."; Entferne diese 3 Punkte. – halojoy

+0

Ja, aber wie kann ich all diese Ergebnisse begrenzen und dann am letzten Ergebnis 3 Punkte setzen? – DotComBoy

Antwort

0

Wie gesagt von @halojoy in Kommentar, die drei Punkte "..." sind in einer Spanne in Ihrem Code. Sie haben diesen Code in eine foreach-Schleife geschrieben, so dass die Punkte bei jeder Iteration geschrieben werden.

Ich werde versuchen, den fast gleichen Code wie Sie in der Lösung zu nutzen:

<?php 
$PageSqla = "SELECT * FROM `table` WHERE status = 'online' ORDER BY nome ASC LIMIT 0,20"; //Note the limit to 20 elements 
$jogadoresonline = mysqli_query($connectionae, $PageSqla); 
echo "<div class='bundinhabonita'>Players online - (".mysqli_num_rows($jogadoresonline).")</div>"; 


if(mysqli_fetch_array($jogadoresonline)){ 
    foreach($jogadoresonline as $merda){ 
     if($merda['grupo'] == "CEO"){ 
      mimimi = "<span style='font-weight: bold;color: #D9A334;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "Manager"){ 
      $mimimi = "<span style='font-weight: bold;color: #aa0000;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "Admin"){ 
      $mimimi = "<span style='font-weight: bold;color: #ff5555;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "Moderator"){ 
      $mimimi = "<span style='font-weight: bold;color: #00aa00;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "Helper"){ 
      $mimimi = "<span style='font-weight: bold;color: #E3D628;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "Builder"){ 
      $mimimi = "<span style='font-weight: bold;color: #3F3FFE;background: transparent url(https://i.imgur.com/DeeiUkd.gif); text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "YouTuber"){ 
      $mimimi = "<span style='font-weight: bold;color: #ff5555; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "MVP+"){ 
       $mimimi = "<span style='font-weight: bold;color: #3ffe3f; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "MVP"){ 
      $mimimi = "<span style='font-weight: bold;color: #00aa00; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "VIP+"){ 
      $mimimi = "<span style='font-weight: bold;color: #be00be; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "VIP"){ 
      $mimimi = "<span style='font-weight: bold;color: #00bebe; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     } elseif($merda['grupo'] == "Member"){ 
      $mimimi = "<span style='font-weight: bold;color: #bebebe; text-shadow: #000000 1px 1px 3px;'><a href='usuario?nome=".$merda['nome']."'>".$merda['nome']."</a></span><span style='color: black;'>, </span>"; 
     }    
    } 
    echo $mimimi."<span style='color: black;'>...</span>"; 

} else{ 
    echo "<div style='color: grey;'>None is online.</div>"; 
} 

Wie Sie im Code sehen können, ist es fast das gleiche wie Sie. Die einzigen Änderungen sind:

  • LIMIT 0,20 in der SQL-Abfrage. Es braucht also die 20 ersten Elemente oder weniger, wenn es nicht mindestens 20 Elemente gibt.
  • Ich bewegte das '...' nach der foreach, so zeigt es Ihre Ergebnisse und erst dann zeigt es die Punkte.