I am working on a project where I first was only designing the theme. However, I now need to create 5 already made custom pages or blocks in a page, which will be available as soon as theme is enabled.
Each page should hold its own code for grabbing information from external database. Now I am having a huge dilemma on deciding how to create those pages. Since there are DB calls made on each of them, I was suggested to create a custom module, which would display a block with the printed content from database. I tried creating "pvpstats.module" and "pvpstats.info" as normal for custom modules, and displaying it in sidebar_first. After I enable the module, nothing happens. The block is just not visible. I used the code below.
function pvpstats_block_info() {
$blocks['pvpblock'] = array(
'info' => t('Example Block'),
'status' => TRUE,
'region' => 'sidebar_first',
'weight' => 0,
'visibility' => 0,
'pages' => 'admin*
coder*
node/add*
node/*/edit
node/*/devel
',
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function pvpstats_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'pvpblock':
$block['subject'] = t('Block Name');
$block['content'] = theblock_contents();
break;
}
return $block;
}
function theblock_contents() {
return '
$dbserver="serveradress";
$dblogin="username";
$dbpass="dbpassword";
$dbname="databaseserver";
mysql_connect($dbserver, $dblogin, $dbpass);
mysql_select_db($dbname);
mysql_query("SET NAMES 'utf8'");
$vypis = mysql_query("SELECT * FROM characters WHERE (accesslevel < '1') AND (pvpkills > '0') order by pvpkills desc LIMIT 20");
echo '<table><tr><td><center>Nick</center></td><td></td><td>Kills</td></tr>';
while($row = mysql_fetch_array($vypis))
{
echo '<tr><td><font color="green">';
echo $row["char_name"];
echo '</font></td><td> </td><td><font color="blue">';
echo $row["pvpkills"];
echo '</font></td></tr>';
}
echo '</table>';
?>
The main point is that I need those blocks later included in my theme so that they are visible immediately after enabling the theme, if that is somehow possible.
theblock_contents()
, since that is not Drupal code. You don't call anymysql_
function in a module.