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

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,230
  • Total Topics: 21,353
  • Online today: 446
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 116
  • Total: 116

Random PHP in block.

Started by steve46, March 19, 2007, 08:57:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

steve46

Hi, im trying to have a block which will randomly pick some PHP code to display. I can get it so that it randomly display html, but i need it to display things like this (for the arcade):

//number of games to show
$no=6;

//number if icons accross
$icons_per_row = 3;

//----------------------------------------------------------------------------
$random_games_choice = rand(1,4);
$games_choice = 'games'.$random_games_choice;
$curr_position = 0;
$games_choice($no,$curr_position,$icons_per_row);

Function games3($no,$curr_position,$icons_per_row)
{
global $scripturl,$db_prefix,$modSettings;
//show the latest games
echo '<div align="center">Latest Games<br />
<table cellpadding="2" cellspacing="5">
<tr>';

$sql = "SELECT ID_GAME, gameName, thumbnail, gameDirectory
FROM {$db_prefix}arcade_games
ORDER BY ID_GAME DESC , gameName ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
while($game = mysql_fetch_array($result))
{
$game_thumb = !$game['gameDirectory'] ? $modSettings['gamesUrl']."/".$game['thumbnail'] : $modSettings['gamesUrl'].$game['gameDirectory']."/".$game['thumbnail'];
if($curr_position == $icons_per_row)
{
echo '</tr><tr>';
$curr_position=0;
}
echo'
<td>
<a href="'.$scripturl.'?action=arcade;sa=play;game='.$game['ID_GAME'].'">
<img src="'.$game_thumb.'" border="0" alt="'.$game['gameName'].'" width="40" height="40" title="Play '.$game['gameName'].'"/></a>
</td>';
$curr_position++;
}
mysql_free_result($result);

echo '
</tr>
</table></div>';
}

Function games1($no,$curr_position,$icons_per_row)
{
//show most played games (one score version only)
global $scripturl,$db_prefix,$modSettings;

echo '<div align="center">Most Played<br />
<table cellpadding="2" cellspacing="5">
<tr>';

$sql = "SELECT ID_GAME, gameName, thumbnail, gameDirectory
FROM {$db_prefix}arcade_games
ORDER BY numPlays DESC , gameName ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
while($game = mysql_fetch_array($result))
{
$game_thumb = !$game['gameDirectory'] ? $modSettings['gamesUrl']."/".$game['thumbnail'] : $modSettings['gamesUrl'].$game['gameDirectory']."/".$game['thumbnail'];
if($curr_position == $icons_per_row)
{
echo '</tr><tr>';
$curr_position=0;
}
echo'
<td>
<a href="'.$scripturl.'?action=arcade;sa=play;game='.$game['ID_GAME'].'">
<img src="'.$game_thumb.'" border="0" alt="'.$game['gameName'].'" width="40" height="40" title="Play '.$game['gameName'].'"/></a>
</td>';
$curr_position++;
}
mysql_free_result($result);

echo '
</tr>
</table></div>';
}


Function games4($no,$curr_position,$icons_per_row)
{
//show least played games (one score version only)
global $scripturl,$db_prefix,$modSettings;
echo '<div align="center">Least Played<br />
<table cellpadding="2" cellspacing="5">
<tr>';

$sql = "SELECT ID_GAME, gameName, thumbnail, gameDirectory
FROM {$db_prefix}arcade_games
ORDER BY numPlays ASC , gameName ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
while($game = mysql_fetch_array($result))
{
$game_thumb = !$game['gameDirectory'] ? $modSettings['gamesUrl']."/".$game['thumbnail'] : $modSettings['gamesUrl'].$game['gameDirectory']."/".$game['thumbnail'];
if($curr_position == $icons_per_row)
{
echo '</tr><tr>';
$curr_position=0;
}
echo'
<td>
<a href="'.$scripturl.'?action=arcade;sa=play;game='.$game['ID_GAME'].'">
<img src="'.$game_thumb.'" border="0" alt="'.$game['gameName'].'" width="40" height="40" title="Play '.$game['gameName'].'"/></a>
</td>';
$curr_position++;
}
mysql_free_result($result);

echo '
</tr>
</table></div>';
}


Function games2($no,$curr_position,$icons_per_row)
{
//show best rated games
global $scripturl,$db_prefix,$modSettings;
echo '<div align="center">Top Rated<br />
<table cellpadding="2" cellspacing="5">
<tr>';

$sql = "SELECT ID_GAME, gameName, thumbnail, gameDirectory
FROM {$db_prefix}arcade_games
ORDER BY gameRating DESC , gameName ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
while($game = mysql_fetch_array($result))
{
$game_thumb = !$game['gameDirectory'] ? $modSettings['gamesUrl']."/".$game['thumbnail'] : $modSettings['gamesUrl'].$game['gameDirectory']."/".$game['thumbnail'];
if($curr_position == $icons_per_row)
{
echo '</tr><tr>';
$curr_position=0;
}
echo'
<td>
<a href="'.$scripturl.'?action=arcade;sa=play;game='.$game['ID_GAME'].'">
<img src="'.$game_thumb.'" border="0" alt="'.$game['gameName'].'" width="40" height="40" title="Play '.$game['gameName'].'"/></a>
</td>';
$curr_position++;
}
mysql_free_result($result);

echo '
</tr>
</table></div>';
}

echo '<br>';

//-------START-------------
/*
|----------------------------------
SMF ARCADE SCROLLING CHAMPS BLOCK for SMFARCADE V2
by Eric Lawson
|----------------------------------
Made for TinyPortal and SMF forum

*/
//Upload a pic called arcade_block.gif (you can use you own gif - just name it arcade_block.gif)
//to your Themes/<themename>/images/ folder

// -- SETUP EDITS ---

$no = 10; //number of top players to show

// --LANGUAGE EDITS --
$txtplay = "The Top Players"; // change "The Top Players" to your language
$txtwin = "Number Of Wins :";// change "Number Of Wins :" to your language
$txtlate = "Latest High Score by ";// change "Latest High Score set by" to your language
$txtwit = "with ";// change "with" to your language
$txton = "on ";// change "on" to your language

global $scripturl,$sourcedir,$boardurl,$db_prefix,$modSettings;
require_once($sourcedir.'/ArcadeStats.php');

//Get newest champ or die
$sql = "SELECT game.ID_GAME, game.gameName, game.thumbnail, game.gameDirectory,
        IFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, IFNULL(mem.realName,'') AS realName, score.score
        FROM {$db_prefix}arcade_scores AS score
        LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = score.ID_MEMBER)
        JOIN {$db_prefix}arcade_games AS game ON (game.ID_GAME = score.ID_GAME)
        ORDER BY `championFrom` DESC
        LIMIT 0,1";
if(!($result = db_query($sql,__FILE__,__LINE__)))
{
die("Could not get the newest champ");
}
$row = mysql_fetch_assoc($result);
mysql_free_result($result);

if(isset($row['gameDirectory']))
{
$row['gameDirectory']=$row['gameDirectory']."/";
}

//newest champ details
$playerid = $row['ID_MEMBER'];
$player = $row['realName'];
$game_id = $row['ID_GAME'];
$game_name = $row['gameName'];
$score = $row['score'];
$game_pic = $modSettings['gamesUrl'].$row['gameDirectory'].$row['thumbnail'];

$bp=ArcadeStats_BestPlayers($no);

$score_poss=0; //players position

?>

<script type="text/javascript">

/***********************************************
* Cross browser Marquee II- Ã,© Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var delayb4scroll=2000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed=1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit=1 //Pause marquee onMousever (0=no. 1=yes)?

////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var actualheight=''

function scrollmarquee(){
if (parseInt(cross_marquee.style.top)>(actualheight*(-1)+8))
cross_marquee.style.top=parseInt(cross_marquee.style.top)-copyspeed+"px"
else
cross_marquee.style.top=parseInt(marqueeheight)+8+"px"
}

function initializemarquee(){
cross_marquee=document.getElementById("vmarquee")
cross_marquee.style.top=0
marqueeheight=document.getElementById("marqueecontainer").offsetHeight
actualheight=cross_marquee.offsetHeight
if (window.opera || navigator.userAgent.indexOf("Netscape/7")!=-1){ //if Opera or Netscape 7x, add scrollbars to scroll and exit
cross_marquee.style.height=marqueeheight+"px"
cross_marquee.style.overflow="scroll"
return
}
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}

if (window.addEventListener)
window.addEventListener("load", initializemarquee, false)
else if (window.attachEvent)
window.attachEvent("onload", initializemarquee)
else if (document.getElementById)
window.onload=initializemarquee


</script>
<?php
echo '<table width="100%">
<tr>
<td align="center">
<br />
<a href="'
,$scripturl,'?action=arcade"><img src="',$settings['images_url'],'/arcade_block.gif" border= "0" alt="Arcade" /></a>
<br /><br/>
</td>
</tr>
</table>
<div id="marqueecontainer" style="position: relative; width: 95%; height:230px; overflow: hidden; border: 0px; padding: 2px; padding-left: 4px;" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">
<div id="vmarquee" style="position: absolute; width: 98%;">
<div align="center">
<a href="'
,$scripturl,'?action=arcade;sa=play;game=',$game_id,'"><img src="',$game_pic,'" border="0" alt="',$game_name,'" width="60" height="60"/></a>
<br />'
,$txtlate,'<br />
<a href="'
,$scripturl,'?action=profile;u=',$playerid,'">',$player,'</a>
<br/>'
,$txtwit,' ',$score,' ',$txton,'<br />',$game_name,'
<br />------------------<br />'
,$txtplay,'<br /><br />';
foreach ($bp as $out)
{
$score_poss++;
echo '',$score_poss,' - ',$out['link'],'<br />',$txtwin,' ',$out['champions'],'
    <br /><br />'
;
};
echo '</div>
</div>
</div>'
;


I have tried all sorts of things, but always ended up short, would really appreciate some help.

Thanks.

G6Cad

You have a snippet allready in here in the snippets board that will show both randome games from the arcade.

Look for arcade in a block

Lesmond

Also did you use a PHP block for your code?

steve46

#3
Im not wanting an arcade block, already have that, it was just an example. i was wanting a block that is 3 blocks in one, so that only one of these blocks would show up at a time at random. the three being:

1) Arcade Block
2) Pandora Bots Block
3) Scolling RSS Feed

i have found the way to do it now. thanks for replying, and sorry i wasnt clear.

steve46

#4
Ive had a request for this code, so i thought i would give it to everyone.

Im pretty sure this is isnt going to be wonderfully coded, but its what i came up with that worked with the already random component of the arcade block you see above.

create a new php block.

echo'
//enter any extra scripts needed here, i used Cross browser Marquee II, and also the functions for the random arcade block.
';

$random_block_choice = rand(1,3);
$block_choice = 'block'.$random_block_choice;

if ($block_choice == 'block1')
{
//First Block content goes here
}
if ($block_choice == 'block2')
{
//Second Block content goes here
}
if ($block_choice == 'block3')
{
//Third Block content goes here
}


quite simple, but has helped me alot.


[edit] that code was bring up errors as i hadnt put ''s around the block1 etc, ie had if ($block_choice == block3), when it should be if ($block_choice == 'block3')

have changed the above code, all is working well with no errors

This website is proudly hosted on Crocweb Cloud Website Hosting.