Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Passing Arrays (again)

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
furious5
Smarty Rookie


Joined: 06 Sep 2004
Posts: 16

PostPosted: Fri Oct 15, 2004 11:06 am    Post subject: Passing Arrays (again) Reply with quote

Since my last post I've had a bit of a play around with SMARTY and have an understanding of its core functionality.

Whilst I designed a db, I populated some 2d arrays and pulled the test information from these without any problems.

Example array:
Code:

Array ( [a] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) [b] => Array ( [0] => test3 [1] => test4 ) [c] => Array ( [0] => test5 [1] => test6 ) )


Using the following code:
Code:

$smarty->assign('test', $test);


When I now come to pass an array created from an SQL query, I find the array is not being passed.

Example array:
Code:

Array ( [id] => 121 [venue_id] => 121 [startdate] => 2004-02-25 [enddate] => 2004-02-29 [country] => Us [name] => Roundhay golf club )


Using the following code:
Code:

$smarty->assign('test', $test);


Can anyone point me in the direction of how I can overcome this problem??


Last edited by furious5 on Wed May 05, 2010 10:38 pm; edited 1 time in total
Back to top
View user's profile Send private message
furious5
Smarty Rookie


Joined: 06 Sep 2004
Posts: 16

PostPosted: Fri Oct 15, 2004 1:04 pm    Post subject: Reply with quote

Actually having looked at this more, I don't think it is the structure of the array, that is causing the problem.

More the fact that array is not being passed, or any value for that matter.

The way I have my framework set up, is that I have one overall page which pulls in the neccesarry templates and included in the templates are includes to module items which perform interaction with the backend.

Currently my code looks like this in the module:
Code:

// Include Global Connection File
require_once("../config/configs/connect.php");

// Set Global Variables
global $smarty;         # Smarty Object
global $test;          # Events Array

// Search for events which are going to happen and display name, date and location
$sql = "SELECT * FROM event";
      
$sql_result = mysql_query($sql, $link) or die(mysql_error());
$row = mysql_fetch_assoc($sql_result);
$num_rows = mysql_num_rows($sql_result);

if($num_rows > 0)
{
   $smarty->assign_by_ref("test", $test);
}

________
Honda CBR150R history

Last edited by furious5 on Tue Feb 01, 2011 2:28 am; edited 2 times in total
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Fri Oct 15, 2004 1:10 pm    Post subject: Reply with quote

you actually don't seem to fill $test with anyting on the php-side.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
furious5
Smarty Rookie


Joined: 06 Sep 2004
Posts: 16

PostPosted: Mon Oct 18, 2004 8:39 am    Post subject: Reply with quote

Hmm yes, I do see your point.

Even if I change the code to this:
Code:

if($num_rows > 0)
{
   $smarty->assign_by_ref("test", $row);
}


When I run SMARTY Debug I can not see the variable.

If I include the module within the index.php I can get the array I'm passing, so somewhere along the way I must be missing something fairly fundamental. Any ideas, anyone??

________
Bandit Series

Last edited by furious5 on Tue Feb 01, 2011 2:28 am; edited 2 times in total
Back to top
View user's profile Send private message
kills
Smarty Elite


Joined: 28 May 2004
Posts: 493

PostPosted: Mon Oct 18, 2004 10:25 am    Post subject: Reply with quote

Code:

// Include Global Connection File
require_once("../config/configs/connect.php");

// Set Global Variables
global $smarty;         # Smarty Object
global $test;          # Events Array

// Search for events which are going to happen and display name, date and location
$sql = "SELECT * FROM event";
     
$sql_result = mysql_query($sql, $link) or die(mysql_error());

if(mysql_num_rows($sql_result) > 0)
{
   $test = array();
   while( $row = mysql_fetch_assoc($sql_result)) {
       $test[] = $row;
   }
   $smarty->assign("test", $test);
}
Back to top
View user's profile Send private message
furious5
Smarty Rookie


Joined: 06 Sep 2004
Posts: 16

PostPosted: Mon Oct 18, 2004 10:35 am    Post subject: Reply with quote

Thanks for this, however this has still not solved my problem.

At the moment although I can run the query and build an array, when the array is being assigned to a variable for smarty to handle the variable is lost.

Perhaps there is something perculiar to my set up, as to why this is happening.

________
og kush pictures


Last edited by furious5 on Tue Feb 01, 2011 2:28 am; edited 2 times in total
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Oct 18, 2004 2:00 pm    Post subject: Reply with quote

Put a {debug} into your template so you can verify the passed values.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP