Dave-ahfb |
07-23-2011 04:36 PM |
First let me say that I am not PHP literate, but can find my way around 9 times out of 10.
I am creating custom templates to include my non vb scripts but am having troubles when trying to include a variable(?) from this script in any template outside the main body.
I will try to be as detailed as possible, hopefully any responses will include the information I give as a real life example so that I can get an understanding of what was done.
Goal: to take $companyname from the below script and add it to my page title, navbits etc. (currently I only get echos of $companyname or {vb:raw companyname}, depending on where I am in my efforts.
PHP Code:
if (isset($_GET['company']))
$company = $_GET['company'];
else
$company = '100megs';
$result = mysql_query("select * from hostwebhost where companyname = '$company'");
if (!$result) {
$numrows = 0;
} else {
$numrows = mysql_num_rows($result);
}
for($x=0;$x<$numrows;$x++){
while ($row = mysql_fetch_array($result)){
$host_id = $row[0];
$companyname = $row[1];
$emailaddress = $row[2];
$URL = $row[3];
$track = $row[4];
$imgtop = $row[5];
$imgright = $row[6];
$imgbody = $row[7];
$joined = $row[8];
$password = $row[9];
$isvalid = $row[10];
$supportlist = $row[11];
$street1 = $row[12];
$street2 = $row[13];
$city = $row[14];
$state = $row[15];
$zip = $row[16];
$country = $row[17];
$contactname = $row[18];
$contactphone = $row[19];
$contactfax = $row[20];
$suggested = $row[21];
$comdescrip = $row[22];
$registered = $row[23];
plugin info:
PHP Code:
location: global_bootstrap_init_start
title: Webhost-php Include
execution order: 5
code:
ob_start();
ob_start();
include('/srv/www/findnewhosting.com/public_html/webhost1.php');
$webhost = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('webhost-php', array('webhost' => $webhost));
As you can see the script is webhost1.phpwhich includes the first set of code above. Please note that the custom page is webhost.php which contains the following:
PHP Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT', 'webhosting');
define('CSRF_PROTECTION', true);
// change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array('webhost-php',);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
chdir ('/srv/www/findnewhosting.com/public_html');
require_once('/srv/www/findnewhosting.com/public_html/global.php');
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
$navbits = construct_navbits(array('' => ' </span></li><li class="navbit"><span><a href="/">Home</a></span></li><li class="navbit"><span><a href="../hostindex.php">Web Hosting</a></span></li><li class="navbit lastnavbit"><span>{vb:raw companyname}
'));
$navbar = render_navbar_template($navbits);
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = '$companyname';
$templater = vB_Template::create('headerincludea');
$headerincludea = $templater->render();
$templater = vB_Template::create('webhost-php');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
$templater->register('sidebarext', $sidebarext);
$templater->register('sidebaropen', $sidebaropen);
$templater->register('headerincludea', $headerincludea);
print_output($templater->render());
?>
webhost-php(template):
PHP Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
<title>{vb:raw companyname}</title>
{vb:raw headerincludea}
{vb:raw headinclude_bottom}
</head>
<body>
{vb:raw header}
{vb:raw navbar}
{vb:raw sidebaropen}
<br />
<div id="pagetitle">
<h1> {vb:raw pagetitle}</h1><br />
</div>
<div class="blockbody">
<div class="blockrow">
<div align="center">
{vb:raw webhost}
</div>
</div>
</div>
{vb:raw sidebarext}
{vb:raw footer}
</body>
</html>
If there is any other info I can give to make it easier to solve just let me know.
Dave
|