Hello,

        Be for warned that I am new to smarty and for some reason I'm
finding it very difficult to learn.  ???  Anyway, my question is how do
I access an array of associative arrays via the {section} statement?

Heres the code:

PHP:

Function readComment( &$smarty, $bid ) {

  ...

  // this code is contained within a class that uses pear db.
  // I pass by reference the smarty object that was created
  // in the main php script.  I have already performed the
  // sql query and checked for any db errors, heres how the
  // data gets assigned.

  while( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) {
    $rowdata[$i] = $row;
    $i++;
  }
  $db->disconnect();
  $smarty->assign("comments", $rowdata);
}


TPL:

<HTML>
<TITLE>Smarty Test</TITLE>
<BODY>
{* $action is assigned to smarty in the main php script. *}
{if $action eq "read"}
  {if count($comments) gt 0}
    {strip}
      <table align="center" border="1">
        <tr><th>nick</th><th>comment</th></tr>
          {section name=idx loop=$comments}
            <tr bgcolor="{cycle values="#cccc99,#d0d0d0"}">
              <td>{$comments[idx].nick}</td>
              <td>{$comments[idx].comment}</td>
            </tr>
          {sectionelse}
            <tr><td colspan="2">sorry, no data avaliable</td></tr>
          {/section}
      </table>
    {/strip}
  {else}
    <center>sorry, no data avaliable</center>
  {/if}
{else}
  <center>action != read</center>
{/if}
</BODY>
</HTML>


TIA,
Matt


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.391 / Virus Database: 222 - Release Date: 9/19/2002
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to