• Please remember to wrap not safe for work text/images in [NSFW][/NSFW] tags.
    Example: [NSFW][img]http://darklygaming.com/images/spinnysgapedass.jpg[/img][/NSFW]

Need some php help

Status
Not open for further replies.

Propaganda

TD Member
[quote1256199698=Nick P!]
I know PHP. Post any problems here (if you can) and I will try to help.
[/quote1256199698]

Who are you?
 

Propaganda

TD Member
Ok it's a top10 hlstats block for the site. It shoudl not use <?php and ?> tags, bbcode uses
PHP:
 tags instead. When I change the tags the block doesn't display. I posted the code over at e07 forums and one guy said 

"There is a lot of code that does not belong there.
For example indeed when u use [php] you should avoid <?php and ?>

Furthermore avoid html and body tags and rewrite the code to use internal e107 database classes."

Indeed the scripts does work as you can see [url]www.torontodarkly.ca/hlstatsx/top10.php[/url]

I would can simply add the code to a custom menu for it to display, or it can be written as a block. Anyway here's the code.

[code]<?php
/*
Script written by stachi
Contact: [email]stachi@gfbg-clan.de[/email]
Version: 1.3
   
No Copyright feel free to use and edit.
*/
  define('IN_HLSTATS', true);
 
  require('config.php');
  require(INCLUDE_PATH . "/class_db.php");
  require(INCLUDE_PATH . "/functions.php");
 
  $db_classname = 'DB_' . DB_TYPE;
  if ( class_exists($db_classname) ) {
    $db = new $db_classname(DB_ADDR, DB_USER, DB_PASS, DB_NAME, DB_PCONNECT);
  }else{
    error('Database class does not exist.  Please check your config.php file for DB_TYPE');
  }
 
  $game = 'css'; 
  if ((isset($_GET['game'])) && (is_string($_GET['game'])))
    $game = valid_request($_GET['game'], 0);

  if ((isset($_GET['server_id'])) && (is_numeric($_GET['server_id'])))
    $server_id = valid_request($_GET['server_id'], 1);
   
  $background_color = '000000';
  if (isset($_GET['bg_color']))
    $background_color = valid_request($_GET['bg_color'], 0);
   
  $color = 'ffffff';
  if ((isset($_GET['color'])) && (is_string($_GET['color'])))
    $color = valid_request($_GET['color'], 0);

   $player_data_query = $db->query("
      SELECT
      lastName,
      skill,
      kills,
      deaths,
      playerId,
      flag
      FROM
      hlstats_Players
    WHERE
      game='$game'
    ORDER BY
      skill desc
    LIMIT
      0,10");
     
  if (empty($server_id)) {
    $server_data_query = $db->query("
      SELECT
        IF(publicaddress != '', publicaddress, concat(address, ':', port)) AS addr,
        publicaddress,
        map_started,
        act_map,
        act_players,
        max_players
      FROM
        hlstats_Servers
      WHERE
        game='$game'");
  }else{
    $server_data_query = $db->query("
      SELECT
        IF(publicaddress != '', publicaddress, concat(address, ':', port)) AS addr,
        publicaddress,
        map_started,
        act_map,
        act_players,
        max_players
      FROM
        hlstats_Servers
      WHERE
        serverId='$server_id'");
  }   
  $server_data = $db->fetch_array($server_data_query);
 
  $maptime = time()-$server_data['map_started'];
  $maptimehours = sprintf("%02d", floor($maptime / 3600));
   $maptimemin   = sprintf("%02d", floor(($maptime % 3600) / 60));
   $maptimesec   = sprintf("%02d", floor($maptime % 60));
?>

<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>
<html xmlns=&quot;[url]http://www.w3.org/1999/xhtml&quot;[/url] lang=&quot;en&quot; xml:lang=&quot;en&quot; >
  <head>
    <title>TOP 10</title>
    <meta http-equiv=&quot;Content-type&quot; content=&quot;text/html;charset=UTF-8&quot; />
    <style type=&quot;text/css&quot;>
      <!--
      a:link, a:visited, a:active {
      font-size: 11px;
      color: #&lt;?php echo $color; ?>;
      text-decoration:none;
      }
     
      a:hover {
      text-decoration:underline;
      }

      table {
        background-color: #&lt;?php echo $background_color; ?>;
        color:#&lt;?php echo $color; ?>;
        font-size: 7pt;
        width:210px;
      }
       
      .head {
        height:125px;
        background-image:url('hlstatsimg/top10.jpg');
      }
      -->
    </style>
  </head>
  <body>
    <table class=&quot;head&quot; style=&quot;color:#000000; font-weight:bold; font-family:Verdana;&quot; align=&quot;center&quot;>
      <tr>
        <td style=&quot;padding-right:0px; padding-left:6px; padding-top:29px;&quot;>&lt;?php echo $server_data['act_map']; ?></td>
        <td style=&quot;text-align:right; padding-right:6px; padding-top:29px;&quot;>&lt;?php echo $maptimehours.':'.$maptimemin.':'.$maptimesec; ?></td>
      </tr>
      <tr>
        <td style=&quot;padding-right:0px; padding-left:6px; padding-top:7px;&quot;>&lt;?php echo $server_data['act_players'].'/'.$server_data['max_players']; ?></td>
      </tr>
      <tr>
        <td style=&quot;padding-right:0px; padding-left:6px; padding-top:8px; padding-bottom:6px;&quot;>&lt;?php echo '<a style=&quot;font-size:7pt; color:#000000;&quot; href=&quot;steam://connect/'.$server_data['addr'].'&quot;>'.$server_data['addr'].'</a>'; ?></td>
      </tr>
    </table>
    <table align=&quot;center&quot;>

      &lt;?php
        $rank=&quot;0&quot;;
        while($row = $db->fetch_array($player_data_query)) {
          $flagge = $row['flag'];
          if (empty($flagge))
            $flagge=&quot;0&quot;;
          $flagge = strtolower($flagge);
          $row['flagge'] = '<img border=&quot;0&quot; alt=&quot;'.$flagge.'&quot; src=&quot;hlstatsimg/flags/'.$flagge.'.gif&quot; />';
          $iduser = $row['playerId'];
          $row['nick'] = '<a target=&quot;_blank&quot; href=&quot;hlstats.php?mode=playerinfo&amp;player='.$iduser.'&quot;>'.$row['flagge'].$row['lastName'].'</a>';
          $rank=$rank+1;
          echo &quot;<tr><td>&quot;.$rank.&quot;.</td><td>&quot;.$row['nick'].&quot;</td><td>&quot;.$row['skill'].&quot;</td></tr>&quot;;
        }
      ?>
       
    </table>
  </body>
</html>[/code]
 

auron

TD Admin
The code that you posted is the source for top10.php, yes? And that works fine. So the problem occurs when you try to embed it in the forums? What happens?
 

auron

TD Admin
See if this gives you any different results.

Code:
[php]
/*
Script written by stachi
Contact: [url="'javascript:window.location=&quot;mai&quot;+&quot;lto:&quot;+&quot;stachi&quot;+&quot;@&quot;+&quot;gfbg-clan.de&quot;;self.close();'"]-email-[/url]
Version: 1.3
   
No Copyright feel free to use and edit.
*/
  define('IN_HLSTATS', true);
 
  require('config.php');
  require(INCLUDE_PATH . &quot;/class_db.php&quot;);
  require(INCLUDE_PATH . &quot;/functions.php&quot;);
 
  $db_classname = 'DB_' . DB_TYPE;
  if ( class_exists($db_classname) ) {
    $db = new $db_classname(DB_ADDR, DB_USER, DB_PASS, DB_NAME, DB_PCONNECT);
  }else{
    error('Database class does not exist.  Please check your config.php file for DB_TYPE');
  }
 
  $game = 'css'; 
  if ((isset($_GET['game'])) && (is_string($_GET['game'])))
    $game = valid_request($_GET['game'], 0);

  if ((isset($_GET['server_id'])) && (is_numeric($_GET['server_id'])))
    $server_id = valid_request($_GET['server_id'], 1);
   
  $background_color = '000000';
  if (isset($_GET['bg_color']))
    $background_color = valid_request($_GET['bg_color'], 0);
   
  $color = 'ffffff';
  if ((isset($_GET['color'])) && (is_string($_GET['color'])))
    $color = valid_request($_GET['color'], 0);

   $player_data_query = $db->query(&quot;
      SELECT lastName, skill, kills, deaths, playerId, flag
	  FROM hlstats_Players
	  WHERE game='$game'
    ORDER BY skill desc
    LIMIT 0,10&quot;);
[/php]
 
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>
<html xmlns=&quot;[url]http://www.w3.org/1999/xhtml&quot;[/url] lang=&quot;en&quot; xml:lang=&quot;en&quot; >  
<head>    
	<title>TOP 10</title>    
	<meta http-equiv=&quot;Content-type&quot; content=&quot;text/html;charset=UTF-8&quot; />    
	<style type=&quot;text/css&quot;>
	<!--
      a:link, a:visited, a:active {
      font-size: 11px;
      color: #[php] echo $color; [/php];
      text-decoration:none;
      }
     
      a:hover {
      text-decoration:underline;
      }

      table {
        background-color: #[php] echo $background_color; [/php];
        color:#[php] echo $color; [/php];
        font-size: 7pt;
        width:210px;
      }
       
      .head {
        height:125px;
        background-image:url('hlstatsimg/top10.jpg');
      }
    -->    
	</style>  
</head>  

<body>    
	<table align=&quot;center&quot;>       
	  [php]
        $rank=&quot;0&quot;;
        while($row = $db->fetch_array($player_data_query)) 
		{
			$flagge = $row['flag'];
			if (empty($flagge))
				$flagge=&quot;0&quot;;
			
			$flagge = strtolower($flagge);
			$row['flagge'] = '<img border=&quot;0&quot; alt=&quot;'.$flagge.'&quot; src=&quot;hlstatsimg/flags/'.$flagge.'.gif&quot; />';
			$iduser = $row['playerId'];
			$row['nick'] = '<a target=&quot;_blank&quot; href=&quot;hlstats.php?mode=playerinfo&player='.$iduser.'&quot;>'.$row['flagge'].$row['lastName'].'</a>';
			$rank=$rank+1;
			echo &quot;<tr><td>&quot;.$rank.&quot;.</td><td>&quot;.$row['nick'].&quot;</td><td>&quot;.$row['skill'].&quot;</td></tr>&quot;;
        }
      [/php]    
	  </table>  
</body>

</html>
 

auron

TD Admin
wait... I was just going off what that dude told you but if you're embedding it I don't see why having the &lt;? ?> tags would be a problem. As far as I can tell the
PHP:
 is just for actually putting it into post.

Let me know what your error was with your original file.
 

Propaganda

TD Member
It's not in a post, it's in a menu, someone wo knows better might look at setting it up as a plugin, plugins allow for straight php code, not tags.
 

auron

TD Admin
Well, I would love to help but this is more of a question about the forum/content management system at this point. I can code the shit outta some PHP, but I'm not sure what you're seeing or what the CMS is asking for.
 
Status
Not open for further replies.
Top