For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > October 2004 > Re: [SMARTY] smarty and adodb help please









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] smarty and adodb help please
Boots

2004-10-02, 3:56 am

Hi.

Perhaps because you assigned to $results and not $list?

xo boots

--- Gareth Thomas <garetht@adelphia.net> wrote:
> Apologies if this question has already been asked.I am new to Smarty
> and I
> have spent most of the day trying to get this to work. I am reading
> the
> contents of a table and want to display it in a section, but I just
> get the
> message "Array $list has no entries", which I know it does if I use
> print_r
> in the PHP code. I am sure it's a minor stupidity of mine that's
> causing
> this, any help much appreciated:
>
> PHP script:
>
> <?php
>
> include("../adodb/adodb.inc.php");
>
> include('../Smarty/libs/Smarty.class.php');
>
>
>
> // Set template dir
>
> $smarty->template_dir = 'templates';
>
> // Set compile dir
>
> $smarty->compile_dir = 'templates_c';
>
>
>
> // create object
>
> $smarty = new Smarty;
>
>
>
> $db = NewADOConnection('mysql');
>
> $db->Connect("localhost", "root", "", "test");
>
>
>
> $results = $db->GetAll("SELECT Employee_Id, Employee_Name FROM
> employee");
>
>
>
> if ($results === false) die("failed");
>
>
>
> $smarty->assign('result',$results);
>
> $smarty->display('index.tpl');
>
>
>
> ?>
>
>
>
> Template:
>
>
>
>
>
> <br>
>
> <b>Table Of Employees</b>
>
> <br>
>
> {section name="i" loop=$list}
>
> <b>Name: {$list[i].Employee_Name}; Id:
> {$list[i].Employee_Id}</b><br>
>
> {sectionelse}
>
> <b><br>Array $list has no entries</b>
>
> {/section}

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com