Jump to content
MakeWebGames

Recommended Posts

Posted

I want to code the top 5 players for my game. However I don't know how to implant it to the html...?

I coded the top 5 players..But I need help implanting it.

 

Code -

 

$_SESSION['top_username'] = ' ';
$query = $db->query("SELECT `userid`, `username`, `laston` FROM `users` WHERE `user_level` != '0' && `fedjail` = '0'	ORDER BY `level` DESC LIMIT 5");
while($r=$db->fetch_row($query))
{
$length = 18;
$text = "{$r['username']}" ;
$display = substr($text, 0, $length) ;
$_SESSION['top_username'].= "$display [{$r['userid']}]<br />";
}
$_SESSION['top_userlevel'] = ' ';
$query = $db->query("SELECT `level` FROM `users` WHERE `user_level` != '0' && `fedjail` = '0' ORDER BY `level` DESC LIMIT 5");
while($r=$db->fetch_row($query))
{
$length = 18;
$text = "{$r['level']}" ;
$display = substr($text, 0, $length) ;
$_SESSION['top_userlevel'].= "$display<br />";
}

 

This is how I want it -

[ATTACH=CONFIG]1469[/ATTACH]

 

HTML -

 



echo<<<EOF

<div class="well">
				<div class="sbox-head">Top 5 Players</div>
				<div class="sbox-content">
					<ul style="list-style: none; margin: 0; font-size: 11px;">
						<li style="box-shadow: 0 1px 0 #0b0a0a, 0 2px 0 rgba(255,255,255,.03);">
							<h5 style="font-size: 12px; color: #B09E8F; font-weight: bold; margin: 0; padding: 0;">1. Hattori Hanzo</h5>
							<p style="margin: 0; padding: 0"><b>Clan:</b>  <i>Rogue Ninjaz</i>
							</p>
							<p style="margin: 0; padding: 0"><b>Status:</b>  <span style="color: green">Online now!</span>
							</p>
						</li>
						<li style="box-shadow: 0 1px 0 #0b0a0a, 0 2px 0 rgba(255,255,255,.03);">
							<h5 style="font-size: 12px; color: #B09E8F; font-weight: bold; margin: 0; padding: 0;">2. Date Masamune</h5>
							<p style="margin: 0; padding: 0"><b>Clan:</b>  <i>N/A</i>
							</p>
							<p style="margin: 0; padding: 0"><b>Status:</b>  <span style="color: red">Offline!</span>
							</p>
						</li>
						<li style="box-shadow: 0 1px 0 #0b0a0a, 0 2px 0 rgba(255,255,255,.03);">
							<h5 style="font-size: 12px; color: #B09E8F; font-weight: bold; margin: 0; padding: 0;">3. Xu Wei</h5>
							<p style="margin: 0; padding: 0"><b>Clan:</b>  <i>The Dynasty Warriors</i>
							</p>
							<p style="margin: 0; padding: 0"><b>Status:</b>  <span style="color: green">Online now!</span>
							</p>
						</li>
						<li style="box-shadow: 0 1px 0 #0b0a0a, 0 2px 0 rgba(255,255,255,.03);">
							<h5 style="font-size: 12px; color: #B09E8F; font-weight: bold; margin: 0; padding: 0;">4. Death_Ronin</h5>
							<p style="margin: 0; padding: 0"><b>Clan:</b>  <i>Rogue Ninjaz</i>
							</p>
							<p style="margin: 0; padding: 0"><b>Status:</b>  <span style="color: red">Offline!</span>
							</p>
						</li>
						<li style="box-shadow: 0 1px 0 #0b0a0a, 0 2px 0 rgba(255,255,255,.03);">
							<h5 style="font-size: 12px; color: #B09E8F; font-weight: bold; margin: 0; padding: 0;">5. Kimu Hasabe</h5>
							<p style="margin: 0; padding: 0"><b>Clan:</b>  <i>The Imperial Samurai</i>
							</p>
							<p style="margin: 0; padding: 0"><b>Status:</b>  <span style="color: red">Offline!</span>
							</p>
						</li>
					</ul>
				</div>
			</div>
		</div>

EOF;

1699713491_ScreenShot2014-05-18at13_24_37.png.a66ac5f955d9dc63fe6785918dbb8430.png

Posted (edited)
Just the top 5 players and their level...

 

But I realised I don't want the level but their clan and laston to show...

Which I don't know how to do...

Okay, assume the set-up is as follows;

 

CREATE TABLE users (
 userid int(11) not null auto_increment,
 username varchar(50) not null,
 userlevel smallint(1) not null default 1,
 level int(11) not null default 1,
 clans int(11) not null default 0,
 laston int(11) not null comment 'This should be datetime?',
 PRIMARY KEY(userid)
 );

CREATE TABLE clans(
 clanid int(11) not null auto_increment,
 clanname varchar(50) not null,
 PRIMARY KEY(clanid)
 );

INSERT INTO users (username, clans, laston, level) VALUES ('account1', 1, 1400418911, 2), ('account2', 2, 1400417911, 1), ('account3', 1, 1400418811, 4);

INSERT INTO clans (clanname) VALUES ('clan1'), ('clan2');

 

Then just run this SELECT query;

SELECT u.username, u.level, u.laston, c.clanname
FROM `users` u
INNER JOIN `clans` c
ON u.clans = c.clanid
ORDER BY u.level DESC
LIMIT 5;

 

Or, if you want to convert the timestamp with the SELECT statement, run;

# http://sqlfiddle.com/#!2/c8910/5
SELECT u.username, u.level, FROM_UNIXTIME(u.laston), c.clanname
FROM `users` u
INNER JOIN `clans` c
ON u.clans = c.clanid
ORDER BY u.level DESC
LIMIT 5;

 

Or, an even friendlier date conversion;

# http://sqlfiddle.com/#!2/c8910/10
SELECT u.username, u.level, CONCAT(FROM_UNIXTIME(u.laston, '%h:%i:%s'), ' hours ago') AS laston, c.clanname
FROM `users` u
INNER JOIN `clans` c
ON u.clans = c.clanid
ORDER BY u.level DESC
LIMIT 5;

SQLFiddle

Edited by sniko

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...