DragonPrime - LoGD Resource Community
Welcome Guest
  • Good evening, Guest.
    Please log in, or register.
  • August 23, 2017, 10:02:07 PM
Home Forums News Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
Search

Pages: [1]   Go Down
  Print  
Author Topic: Noob PHP ?...how to display current logged in users and other info on HTML page?  (Read 3343 times)
0 Members and 1 Guest are viewing this topic.
kaiser
Member
Captain of the Guard
***
Offline Offline

Posts: 104


I'm such a n00b


View Profile WWW
« 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?
Logged

ComfortablyDumb Relaunch
Fast days, lots of turns
http://comfortablydumb.net/logd
kickme
Global Moderator
Mod God
*****
Offline Offline

Posts: 1589


Yay for elephants!


View Profile WWW
« Reply #1 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
Logged

Waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka
kaiser
Member
Captain of the Guard
***
Offline Offline

Posts: 104


I'm such a n00b


View Profile WWW
« Reply #2 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! Smiley
« Last Edit: January 13, 2006, 11:56:16 AM by kaiser » Logged

ComfortablyDumb Relaunch
Fast days, lots of turns
http://comfortablydumb.net/logd
kickme
Global Moderator
Mod God
*****
Offline Offline

Posts: 1589


Yay for elephants!


View Profile WWW
« Reply #3 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.
« Last Edit: January 13, 2006, 12:02:52 PM by kickme » Logged

Waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka
XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #4 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"))."'";
Logged

Running for more than three years now:
kickme
Global Moderator
Mod God
*****
Offline Offline

Posts: 1589


Yay for elephants!


View Profile WWW
« Reply #5 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
Logged

Waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka waka
Sichae
iMod God
SVN Users
Mod God
*
Offline Offline

Posts: 3458


If ya didn't get it by now... you're hopeless...


View Profile WWW
« Reply #6 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? Wink

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.
Logged

If you didn't understand anything in the above post, don't try to attempt anything suggested.

XChrisX
Global Moderator
Mod God
*****
Offline Offline

Posts: 4647

Be aware of the squirrel!


View Profile WWW
« Reply #7 on: January 13, 2006, 12:56:34 PM »

you could just include "common.php" in your file Wink then getsetting will work... :p
Logged

Running for more than three years now:
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Play LoGD on Dragonprime

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Recent Topics
DragonPrime LoGD
Who's Online
20 Guests, 0 Users
Home Forums News Downloads Login Register Advanced Search