I've been using .NET for the last 2 years, but I want to try this smarty stuff out. so I 'm having a go, but I'm having a problem with it only printing the first character of my record set.


<?
require 'libs/Smarty.class.php';
include("libs/class.dbconnect.php");
include("configs/dbconfig.php");

$smarty = new Smarty;

$smarty->compile_check = true;
$smarty->debugging = true;

$myConnect = new DBConnect($dbinfo); //create DB OBJECT

$myConnect->connection();	 // Connect to DB Object

$sql = "select user_name from users";  // QUery the DB

$result = $myConnect->db_exe("$sql");  // Execute Query

	while ($row = mysql_fetch_array($result) ){

		   $users[] = $row['user_name'];
  }


$smarty->assign("result", $users);

$myConnect->db_close();

$smarty->display('default.tpl');

?>

now this is my default.tpl

{include file="header.tpl" title="My Smarty in Action"}

<div id=mydiv>


 {section name=i loop=$result}
 	Username: {$result[i].user_name}<br>
 {/section} 

</div>

I only get this as output
username: m
username: j

the debugger is picking up the fact that it's matt, joe but not displaying it as a string.

Any clues to why it's only printing the first characters ?

Thanks in advance

    Very odd, I have Smarty templates which work exactly like that, and work fine. Does the token i somehow refer to a counter (long shot I know) that is perhaps set to 0 ?

      the problem was I was building an array of strings, not associative arrays, so there for when I took off the dropped the username from this
      {$result.user_name} and did this
      {$result} it worked fine.

      I think I need to do something more like this
      array('user_name' => $row['user_name']);

      then I can do {$result.user_name}

      thanks for your help

        Write a Reply...