TinyPortal

Development => Support => Topic started by: Ray on September 20, 2005, 06:07:51 PM

Title: Having php show up in a block
Post by: Ray on September 20, 2005, 06:07:51 PM
Im trrying to add a php to a block and I have the block set to php but the block will not show anything - I have had this problem before just never asked-- here it the code


// Settings
$settings = ""; // SMF Settings file (Must set if not preview-mode or not in smf directory)
$preview = true; // Set FALSE if you include this
// End of settings

if($settings != "") require($settings); else require(dirname(__FILE__) . '/Settings.php');

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


{

//   echo "
".print_r($game,true)."
";

   //echo "
".print_r($top,true)."
";

   foreach($top as $temp){
      echo "{$temp['name']} - {$temp['score']} at ". date("d m y", $temp['stime']) . " by {$temp['realName']}
";;
   }

   echo "<h2>High Game Scores</h2>";
   $top = highscore();
   //echo "
".print_r($top,true)."
";

   foreach($top as $temp){
      echo "{$temp['name']} - {$temp['score']} at ". date("d m y", $temp['stime']) . " by {$temp['realName']}
";;
   }


}

// Functions begin
// All returns array

// random_game( [category id] )
// highscore( [count=10], [game internal name] )



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;
}


function highscore($count = 10, $game = ""){
   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)){
      $top[] = $x;
   }
   return $top;
}

It works ok if you pull it up in a browser
Title: Re: Having php show up in a block
Post by: bloc on September 21, 2005, 01:00:53 AM
It seems the "echo" which contain print_r in it, are commented out? this...

//   echo "

".print_r($game,true)."

";


Should maybe be:

echo "  ".print_r($game,true)." ";
Title: Re: Having php show up in a block
Post by: Ray on September 21, 2005, 02:56:33 AM
Tried that didnt work.

But works ok like this??

Title: Re: Having php show up in a block
Post by: borgBOB on September 23, 2005, 03:42:51 PM
Get this to work Ray? I also installed the arcade mod and may want to add this.
Thanks
Title: Re: Having php show up in a block
Post by: gerrymo on September 23, 2005, 03:46:22 PM
All you echos are commented out. Try changing them all, not just the first one.