PHP Snippets

Discussion in 'Resources' started by TMFKSOFT, Apr 27, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    TMFKSOFT

    Im going to to my best to create php snippets to interact with some plugins via their SQL Databases.
    Such as xAuth, BigBrother and so forth.

    Feel free to reply with your own snippets and see if we can make a collection and maybe a full front end. Something like PHPMyAdmin but for Minecraft.

    I also create small 'APIs' to do things that are a laborious task, feel free to use the 'API' with your PHP Snippets. I intend to keep them running.

    Heres my Minecraft Skin's Face:
    [​IMG]

    xAuth registered users list:
    http://pastebin.com/V1SpgYRp
    Paste it where you would like the list to appear.
    It will create a list of users reigstered and their face displayed to the left.
    Example: http://treecraft.in/
    Code fix pointed out by CypherX

    Thanks,
    Thomas Edwards
     
  2. Offline

    CypherX

    Hi there, I'm like one of those grammar Nazis, but with code!
    • You should use the MySQLi PHP extension.
    • In the SQL query, swap the asterisk (*) with 'playername' (without the quotes) for maximum performance. There's no need to grab all fields if you'll only be using the playername field.

    Anyway, good job.
     
  3. Offline

    TMFKSOFT

    Thanks for letting me in on the Query fix also,
    May i ask for xAuth is it possible to get if a player is online and how? The aXuth URL feature has no docs from what i can find :|
     
  4. Offline

    CypherX

    It's not possible to check if a player is online with xAuth.
     
  5. Offline

    wouter0100

    And you're using mysql_fetch_array, use mysql_fetch_assoc instant.
    assoc is much faster then array.

    If you wanna know if the player is online, use the new function in Minecraft (1.7). Query.
     
  6. Offline

    Double0negative

    Something i threw together for my server real fast, it takes logblock info and displays in on a table. Includes the player, online time, blocks broke/placed

    Note: this is deff not the best way to do this and is very slow (selecting the block data for each user needs to be redone) , i just threw this together for my own purposes.

    Example http://jakebingram.gsv.me/playerstats/

    Code:PHP
    1.  
    2. <?php
    3.  
    4. include 'db_con.php';
    5.  
    6. $sort = $_GET['sort'];
    7. if(!isset($sort)){
    8. $sort = "playerid";
    9. }
    10. $page = $_GET['page'];
    11. $start = $page * 20;
    12. $result = mysql_query("SELECT * FROM `lb-players` ORDER BY $sort DESC LIMIT $start,20 ");
    13.  
    14. }
    15. echo mysql_error();
    16. echo 'Stats are from March 3rd 2012. Block stats are from the main world only';
    17. echo '<center><table border="1"><tr><td>#</td><td><a href="index.php?sort=playerid"> ID</a></td><td><a href="index.php?sort=playername">Player Name<a/></td><td><a href="index.php?sort=onlinetime">Online Time (sec)</td><td>Blocks Placed</td><td>Blocks Destroyed</td></tr>';
    18. $page++;
    19. $id = $start;
    20. while($row = mysql_fetch_array($result)){
    21. $pid = $row['playerid'];
    22. $r = mysql_query("SELECT * FROM `lb-world` WHERE playerid=$pid AND type=0 ");
    23. echo mysql_error();
    24. $r2 = mysql_query("SELECT * FROM `lb-world` WHERE playerid=$pid AND type<>0 ");
    25. echo '<tr>';
    26. echo '<td>',$id, '</td>';
    27. echo '<td>',$row['playerid'],'</td>';
    28. echo '<td>',$row['playername'], '</td>';
    29. echo '<td>',$row['onlinetime'], '</td>';
    30. echo '<td>',mysql_num_rows($r2), '</td>';
    31. echo '<td>',mysql_num_rows($r), '</td>';
    32. echo '</tr>';
    33. $id++;
    34. }
    35. //$page--;
    36. if($page>0){
    37. echo '<a href="index.php?sort=',$sort,'&page=',$page-2,'">Prev</a> | ';
    38. }
    39. echo '<a href="index.php?sort=',$sort,'&page=',$page,'">Next</a>';
    40. ?>
    41.  
     
Thread Status:
Not open for further replies.

Share This Page