TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 18, 2024, 06:54:38 PM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 112
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 59
  • Total: 59

Pulling in high scores from smfarcade into a block. Has anybody tried this?

Started by houston, November 08, 2005, 03:43:51 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


snork13

should be easy enough ;) maybe a random game too, along with a thumb for the game! I'll have a look unless some has done?

ok, here is for a random game, make a php block and add:


require('./Settings.php');


$link = mysql_connect($db_server, $db_user, $db_passwd);
mysql_select_db($db_name, $link);


$game = random_game();


echo "<center><a href=\"index.php?action=arcade;do=play;game={$game['id']}\"><img src=\"{$game['thumbnail']}\" alt=\"{$game['name']}\" /></a><br />
<a href=\"index.php?action=arcade;do=play;game={$game['id']}\">{$game['name']}</a></center>";


// Functions begin
// All returns array

// random_game( [category id] )


function random_game($cat_id = ""){
global $link,$db_prefix,$boarddir,$boardurl;
if($cat_id == ""){
$query = "SELECT * FROM {$db_prefix}games ORDER BY rand() LIMIT 0,1";
}else{
$query = "SELECT * FROM {$db_prefix}games WHERE category='{$cat_id}' ORDER BY rand() LIMIT 0,1 ";
}

$game = mysql_fetch_array(mysql_query($query));
$ext = array('gif','GIF','png','PNG','jpg','JPG',); // Extensions to look for
$game['thumbnail'] = ""; // No thumbnail for default

foreach($ext as $ex){
if(file_exists($boarddir. "/Games/".$game['game'].".".$ex)){
$game['thumbnail'] = $boardurl."/Games/".$game['game'].".".$ex;
}
}

return $game;

}



-snork

edited to fixed the <center></center>

sorry :idiot2:

houston

Wow that was fast. Thanks a lot. Ask a simple question and get a great response. I'll give it a try.

snork13

Quote from: houston on November 08, 2005, 06:00:39 AM
Wow that was fast. Thanks a lot. Ask a simple question and get a great response. I'll give it a try.

it's just for random games, not a champion list...i'll do that next!

-snork



snork13

ok, this will pull the highscores from smfarcade into a php block. So you will need a need php block ;D and in the function highscore($count = 5, $game = "", $cutoff = 0)

// highscore( int [count=10], str [game internal name], int [cutoff older than] )

require('./Settings.php');

$top = highscore();
//echo "<pre>".print_r($top,true)."</pre>";

foreach($top as $temp){

echo"<table align=\"center\" width=\"100%\"><tr><td align=\"center\" class=\"smalltext\">{$temp['realName']}</td></tr>";
echo "<tr><td align=\"center\" class=\"smalltext\">{$temp['name']} - {$temp['score']}</td></tr><tr><td width=\"100%\"><hr></td></tr></table>";
}
function highscore($count = 5, $game = "", $cutoff = 0)
{
global $link,$db_prefix,$boarddir,$boardurl;

if($game == "")
$query = "SELECT * FROM {$db_prefix}games,{$db_prefix}games_high,{$db_prefix}members WHERE {$db_prefix}games.game={$db_prefix}games_high.game AND {$db_prefix}games_high.member={$db_prefix}members.ID_MEMBER ORDER BY score DESC LIMIT 0,{$count}";
else
$query = "SELECT * FROM {$db_prefix}games,{$db_prefix}games_high,{$db_prefix}members WHERE {$db_prefix}games.game={$db_prefix}games_high.game AND {$db_prefix}games_high.member={$db_prefix}members.ID_MEMBER AND {$db_prefix}games.game='{$game}' ORDER BY score DESC LIMIT 0,{$count}";
$res = mysql_query($query) or die(mysql_error());
$top = array();
while($x = mysql_fetch_array($res))
{
$x['score'] = (string)$x['score'];
$top[] = $x;

}
return $top;
}


thank to Niko (mod authur) for the help

houston

Thanks Guys. Really appreciate the hard work and time that you put into this stuff.

Skhilled

Thanks, snork13. I think this is MUCH better than the extra long champions list under everybody's avatar! Saves page space as well.  ;)

Ray