xman_79
03-14-2010, 10:00 PM
Hi , Sorry because my English is weak, but I liked to write a topic on the use of an external database within the Forum's Blocks .
Go to : admincp -> Forums & Moderators -> Forum Blocks Manager -> Add Block : Custom Html / Php
Add new block: Custom HTML/PHP
Title : Your title ;
Description : your description ;
Cache Time (in minutes) : 60;
Content Type : Php
Content : ***
Template to Use : add your template . (eg. block_html)
The content :
//THIS IS NOT THE DATABASE OF VBULLETIN
DEFINE ('DB_USER', 'CHANGE_TO_USER');
DEFINE ('DB_PASSWORD', 'CHANGE_TO_PASSWORD');
DEFINE ('DB_HOST', 'CHANGE_TO_HOST');
DEFINE ('DB_NAME', 'CHANGE_TO_DB_NAME');
if($dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD))
{
if(!mysql_select_db(DB_NAME))
{
return false;
}
}
else
{
return false;
}
ob_start();
$testquery = mysql_query("SELECT * from NAME_OF_TABLE");
$testarray = array();
while($testrow = mysql_fetch_array($testquery))
{
$testarray["$testrow[SOMEID]"] = $testrow;
}
unset($testrow);
mysql_free_result($testquery);
$templater = vB_Template::create('YOUR_TEMPLATE_NAME');
$templater->register('mytestvar', $testarray);
$output .= $templater->render();
$output .= ob_get_contents();
return $output;
ob_end_clean();
The template (YOUR_TEMPLATE_NAME) .
Create a new template .
<ul>
<vb:each from="mytestvar" key="SOMEID" value="testrow">
<li>{vb:raw testrow.somerow}</li>
</vb:each>
</ul>
Eg.
114191
Go to : admincp -> Forums & Moderators -> Forum Blocks Manager -> Add Block : Custom Html / Php
Add new block: Custom HTML/PHP
Title : Your title ;
Description : your description ;
Cache Time (in minutes) : 60;
Content Type : Php
Content : ***
Template to Use : add your template . (eg. block_html)
The content :
//THIS IS NOT THE DATABASE OF VBULLETIN
DEFINE ('DB_USER', 'CHANGE_TO_USER');
DEFINE ('DB_PASSWORD', 'CHANGE_TO_PASSWORD');
DEFINE ('DB_HOST', 'CHANGE_TO_HOST');
DEFINE ('DB_NAME', 'CHANGE_TO_DB_NAME');
if($dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD))
{
if(!mysql_select_db(DB_NAME))
{
return false;
}
}
else
{
return false;
}
ob_start();
$testquery = mysql_query("SELECT * from NAME_OF_TABLE");
$testarray = array();
while($testrow = mysql_fetch_array($testquery))
{
$testarray["$testrow[SOMEID]"] = $testrow;
}
unset($testrow);
mysql_free_result($testquery);
$templater = vB_Template::create('YOUR_TEMPLATE_NAME');
$templater->register('mytestvar', $testarray);
$output .= $templater->render();
$output .= ob_get_contents();
return $output;
ob_end_clean();
The template (YOUR_TEMPLATE_NAME) .
Create a new template .
<ul>
<vb:each from="mytestvar" key="SOMEID" value="testrow">
<li>{vb:raw testrow.somerow}</li>
</vb:each>
</ul>
Eg.
114191