DragonPrime - LoGD Resource Community

Game Administration, Installation and Configuration => Game Administration Chat => Topic started by: kaiser on January 13, 2006, 11:35:57 AM



Title: Noob PHP ?...how to display current logged in users and other info on HTML page?
Post by: kaiser on January 13, 2006, 11:35:57 AM
I'm redoing my site and devoting it entirely to LotGD. On the index page (index.html...not the login page of the game itself) I wanted to display the following:

Who's online now
Newest member name
Latest Hero
total member count


that sort of thing. I'm sure its simple enough to call out to the DB and display the results but ive never done this sort of thing before. Is it as easy as just calling out to the DB and displaying the results (i.e. hack the same DB code in list.php and login.php)? Also...whats the command needed to add up the entries in the settings table and display the sum?


Title: Re:Noob PHP ?...how to display current logged in users and other info on HTML pa
Post by: kickme on January 13, 2006, 11:52:03 AM
1. It would have to be index.php, unless you change your server so that a .html file gets parsed for php.

2. The SQL you'll need:
Who's online:
Code:
SELECT name FROM accounts WHERE loggedin=1
Newest member:
Code:
SELECT value FROM settings WHERE setting='newestplayer'
Then
Code:
SELECT name FROM accounts WHERE acctid='$newest'
(where $newest is what was returned form the previous query)
Latest Hero (if the statue module is active)
Code:
SELECT value FROM module_settings WHERE setting='hero'
Then
Code:
SELECT name FROM accounts WHERE acctid='$hero'
(where $hero is what was returned form the previous query)
Total member count:
Code:
SELECT count(name) FROM accounts
You might have to change the table names if you have a prefix


Title: Re:Noob PHP ?...how to display current logged in users and other info on HTML pa
Post by: kaiser on January 13, 2006, 11:56:01 AM
couldnt i just add an html table with <?php inside to display the PHP inside the html page?

and thank you that was just what i needed! :)


Title: Re:Noob PHP ?...how to display current logged in users and other info on HTML pa
Post by: kickme on January 13, 2006, 12:01:43 PM
It depends on your server.

If you're using apache, and have access to the http.conf file, there should be a line in there something like
Code:
AddType application/x-httpd-php .php .phtml
If it doesn't say .html, then just add that to the end of the line, save and restart apache.

I can't help with other servers as I have no experinace with them.


Title: Re:Noob PHP ?...how to display current logged in users and other info on HTML pa
Post by: XChrisX on January 13, 2006, 12:16:27 PM
2. The SQL you'll need:
Who's online:
Code:
SELECT name FROM accounts WHERE loggedin=1
This one is online slightly correct. If I time-out, my online flag still shows "1". You need this SQL;

Code:
$sql = "SELECT name FROM accounts WHERE loggedin=1 AND laston > '".date("Y-m-d H:i:s",strtotime("-".getsetting("LOGINTIMEOUT",900)." seconds"))."'";


Title: Re:Noob PHP ?...how to display current logged in users and other info on HTML pa
Post by: kickme on January 13, 2006, 12:29:42 PM
This one is online slightly correct. If I time-out, my online flag still shows "1". You need this SQL;

Code:
$sql = "SELECT name FROM accounts WHERE loggedin=1 AND laston > '".date("Y-m-d H:i:s",strtotime("-".getsetting("LOGINTIMEOUT",900)." seconds"))."'";

That would only work if run as part of logd. If it was outside the game, if would need to be
Code:
SELECT value FROM settings WHERE setting='LOGINTIMEOUT'
then
Code:
$sql = "SELECT name FROM accounts WHERE loggedin=1 AND laston > '".date("Y-m-d H:i:s",strtotime("-".$timout." seconds"))."'";
where $timeout is the result of the first query


Title: Re:Noob PHP ?...how to display current logged in users and other info on HTML pa
Post by: Sichae on January 13, 2006, 12:54:46 PM
You would also need to colour sanitize names. LotGD colour codes don't tend to work in real life, now do they? ;)

Next up, you forgot the inclusion of prefixes to databases. So, you will have to require some other files in order to do this, or make sure that the author of such a script remembers to insert this vital information.

If I were this person, I would just adapt the RSS module to do what he wants (Lonny has created something for Xoops that I am sure can be adapted to a simple php/html script). All of that other extraneous information (last hero) shouldn't be needed or if needed, could most likely be cut and paste from other parts of the code or a modification to the rss.php itself.


Title: Re:Noob PHP ?...how to display current logged in users and other info on HTML pa
Post by: XChrisX on January 13, 2006, 12:56:34 PM
you could just include "common.php" in your file ;) then getsetting will work... :p

© 2017 DragonPrime - LoGD Resource Community
Email Talisman: talisman -at- gmail.com
&oeXs)2U7=V BmܲV.U e=;p\}eG )Jj} C5EH7ˤH=j } mo|*Ŋw{drV_@IV>/- TFQJ׀̀Ve}l1,V O iNYx͘$e$;
Forums: Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines