Page 1 of 1

HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 2:27 pm
by AndyGpy
Hi,

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

here is the code

Code: Select all

<?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: Select all

<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.

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 3:30 pm
by Brf
First of all, your variable names have to be upper-case, like this:

Code: Select all

      $template->assign_block_vars('user_row', array( 
                  'LIFE_SPECIES' => $row['species'],
               'LIFE_LATIN' => $row['Latin_ID']
                     )
                  );

second, your code in the template has be enclosed in a block

Code: Select all

<!-- BEGIN user_row -->
...stuff...
<!-- END user_row -->

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 3:46 pm
by AndyGpy
Ok, Done that now i only have one name appearing instead of all names,

Any suggestions on getting round that one ?

regards

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 3:54 pm
by Brf
If you have everything setup properly, you should have one block for each user_row. That is the purpose of the block_vars.

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 3:57 pm
by AndyGpy
so what your saying is this in my .tpl file is wrong ?

<!-- BEGIN user_row -->
<div class="style7 style11 style11 style11">{user_row.LIFE_SPECIES}{user_row.LIFE_LATIN}</div>
<!-- END user_row -->

how do i get a list of all into html ?

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 4:04 pm
by Brf
That should work fine, assuming the rest of the HTML around it is valid too.

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 4:10 pm
by AndyGpy
HTML is :-

<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"><!-- BEGIN user_row -->{user_row.LIFE_SPECIES}<!-- END user_row --><!-- BEGIN user_row -->{user_row.LIFE_LATIN}<!-- END user_row --><br />></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>

The Sprys scripts are in correct folders

have a look at http://www.scotbird.co.uk/ScotBird_Foru ... kindex.php not quite what i am after, ignore the 2009 tab i will work on that next.

Any suggestions ? this is my first PHP project of my own code, so any help would be appreciated.

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 4:12 pm
by Brf
Where are your

Code: Select all

<!-- BEGIn user_row -->
and

Code: Select all

<!-- END user_row -->
??

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 4:14 pm
by Brf
Oh. I see them.... You have them all smashed up in the other lines.
You should have only one BEGIn and one END and they should be on lines by themselves.

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 4:19 pm
by AndyGpy
i have tried that and it has the same effect

<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">
<!-- BEGIN user_row -->
{user_row.LIFE_SPECIES}{user_row.LIFE_LATIN}
<!-- END user_row -->
<br />

</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>

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 4:21 pm
by Brf
That URL you have up there is redirecting to a login page.

Re: HELP -- $template->assign_block_vars

Posted: Mon Dec 29, 2008 4:22 pm
by AndyGpy
YIPPPEEEE

moved the <br /> inside the begin and end statement now it working

cheers

MORE HELP -- $template->assign_block_vars

Posted: Tue Dec 30, 2008 12:54 pm
by AndyGpy
The web page is only open to members, sorry, if needed you can just register and i will delete u later.

I have managed to get most of it working but i could do with help on this last bit.

I have a table with loads of fields updated by the database displying on HTML.

<th scope="col"><span class="style7">{life.LIFE_TICKED}</span></th>
<th scope="col"><input name="checkbox" type="checkbox" checked = "checked" /></th>

One of the cells in the table is a checkbox, i cannot get it to check if life.LIFE_TICKED ( which is boolean ) is true ?

Any suggestions ?

Re: HELP -- $template->assign_block_vars

Posted: Tue Dec 30, 2008 1:01 pm
by Brf
replace:

Code: Select all

<th scope="col"><input name="checkbox" type="checkbox" checked = "checked" /></th>
with

Code: Select all

<th scope="col"><input name="checkbox" type="checkbox" {life.LIFE_TICKED} /></th>
then in your php in your assign_block_vars use

Code: Select all

'LIFE_TICKED' => ($row['lifeticked']) ? 'checked="checked"' : '',

Re: HELP -- $template->assign_block_vars

Posted: Tue Dec 30, 2008 1:10 pm
by AndyGpy
Once again your a scholar !!

Cheers