HELP -- $template->assign_block_vars


Subject: HELP -- $template->assign_block_vars
Hi,

Can someone help me, i have created a Template Page as per the docummetation section,

here is the code

Code: [Download] [Hide] [Select]
<?php
/***************************************************************************
* template.php
* -------------------
* begin : Saturday, Okt 10, 2003
* copyright : (C) 2008 Raimon Meuldijk
* email : Raimon@phpBBservice.nl
*
* $Id: $
*
* Modified by Lopalong 3rd Aug 2008 < http://icythemes.com >.
*
***************************************************************************/

/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . '/ticklists/ticklistconfig.'.$phpEx);


// standard session management
$userdata = session_pagestart($user_ip);

if ((!$userdata['session_logged_in']) )

{
redirect(append_sid(LOGIN_MG . '?redirect=tickindex.' . $phpEx ));

}

else

{
init_userprefs($userdata);
// set page title
$page_title = "Scotbird Ticklists - Members only area !! ";

// standard page header
include($phpbb_root_path . 'includes/page_header.'.$phpEx);

// Connect to the database

$db = new sql_db($ticklist_mysql_host,$ticklist_mysql_username,$ticklist_mysql_password,$ticklist_mysql_db,false);

if(!$db)
{
die("Database Connection Failed:- Please Contact Site Admin" . mysql_error());
}

//Check if user has a ticklist
$result = mysql_query("SHOW TABLES LIKE '".$userdata[username] ."_2009'");
if( !mysql_num_rows($result) )
{
// if not then create them
include_once($phpbb_root_path . '/ticklists/copylist.'.$phpEx);
}


// assign template
$template->set_filenames(array('body' => 'tickindex.tpl'));

$tbl = $userdata[username]."_2009";
$sql = "SELECT * FROM " . $tbl;

$result = $db->sql_query($sql);
if (!($result = $db->sql_query($sql)))
{

die("Database Query Failed" . mysql_error());
}

// This is where you would add a new VARS Array if you intend to use your own custom VARS.

while ( $row = $db->sql_fetchrow($result) )
{

$template->assign_block_vars('user_row', array(
'Life_Species' => $row['species'],
'Life_Latin' => $row['Latin_ID'],
)
);
}



// Build the page
$template->pparse('body');

// standard page footer
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);

}
?>


I have created a template html file which includes a spry tab which works ok

Here is the html file

Code: [Download] [Hide] [Select]
<script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
<link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style4 {font-size: 18px}
.style5 {color: #660000}
.style7 {color: #003300}
.style11 {font-size: 14px}
.style12 {font-size: 16px}
.style13 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
<p class="style7"><strong>Tick Lists of :-</strong> <span class="style13">{username}</span></p>
<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup style5 style11 style11">
<li class="TabbedPanelsTab style7 style12 style11 style11" tabindex="0">Life List</li>
<li class="TabbedPanelsTab style4 style5 style12 style11 style11" tabindex="0">2009 List</li>
</ul>
<div class="TabbedPanelsContentGroup">
<div class="style7 style11 style11 style11">{user_row.Life_Species}{user_row.Life_Latin}</div>
<div class="style5 style11 style11">{2009_Species} {2009_Latin} {2009_Place} {2009_Date} </div>
</div>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<script type="text/javascript">
<!--
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
//-->
</script>


As it is the database query in the tickindex.php file works ok, i have proven it with echo statements, i can transfer data between the 2 files ( PHP to .TPL ) no problem by using single variable type calls

eg

'Life_Species' => 'Hello this is test data'
etc

but i am not getting any data transfer when using the $template->assign_block_vars method.

if i put an echo statement in as shown below, i can see the info is pulled from the data, but i cannot get it to parse to the HTML file.

$template->set_filenames(array('body' => 'tickindex.tpl'));

$tbl = $userdata[username]."_2009";
$sql = "SELECT * FROM " . $tbl;

$result = $db->sql_query($sql);
if (!($result = $db->sql_query($sql)))
{

die("Database Query Failed" . mysql_error());
}

// This is where you would add a new VARS Array if you intend to use your own custom VARS.

while ( $row = $db->sql_fetchrow($result) )
{
echo $row['species']
$template->assign_block_vars('user_row', array(
'Life_Species' => $row['species'],
'Life_Latin' => $row['Latin_ID'],
)
);
}



// Build the page
$template->pparse('body');


Anyone got any advice or help they can give, i am new to PHP and am basically learning as i Go.

The page can be seen here Click here to see

the page may change slightly if your viewing it as i am continuing to try to get it sorted.

Subject: Re: HELP -- $template->assign_block_vars
how to parse ? parse as {X} in tpl and $template->assign_block_vars('user_row', array('X' => $x));

and use "$userdata[username]" is not a very good idea. use addslashes(); and htmlspecialchars();

Profile PM  
Subject: Re: HELP -- $template->assign_block_vars
I have sussed how to do it before your reply.

What do you mean by userdata username special characters, i am new to php so can you please explain a little.

regards


Page 1 of 1


  
You cannot post new topics
You cannot reply to topics
You cannot edit your posts
You cannot delete your posts
You cannot vote in polls
You cannot attach files
You can download files
You cannot post calendar events

   

This is a "Lo-Fi" version of our main content. To view the full version with more information, formatting and images, please click here.

Powered by Icy Phoenix based on phpBB
Generation Time: 0.1833s (PHP: 9% SQL: 91%)
SQL queries: 10 - Debug Off - GZIP Enabled