RE: [PHP] Smarty template question
> http://www.php.net/manual/en/language.types.array.php#language.types.arr > ay.syntax > > > This is done by assigning values to the array while specifying the key > > in brackets. You can also omit the key, add an empty pair of brackets > > ("[]") to the variable-name in that case. > > > $arr[key] = value; > > $arr[] = value; > > // key is either string or nonnegative integer > > // value can be anything > > You really don't have to create $i, it will be created *on the fly*, > works for me. Yes you are correct, sorry that is a hold over from my c++ days. Its just a habit. I figured out my problem, I didn't have my variables "nick & comment" capitalized like they are in the database. Thanks for your help, 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
RE: [PHP] Smarty template question
Was written > > > while( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { > > > $rowdata[$i] = $row; > > > $i++; > > > > I don't think you need the $i. > > I need the $i because I'm assigning the every row from the result into > an array. http://www.php.net/manual/en/language.types.array.php#language.types.arr ay.syntax > This is done by assigning values to the array while specifying the key > in brackets. You can also omit the key, add an empty pair of brackets > ("[]") to the variable-name in that case. > $arr[key] = value; > $arr[] = value; > // key is either string or nonnegative integer > // value can be anything You really don't have to create $i, it will be created *on the fly*, works for me. I took your template and created a simple php script using smarty. It works. Here it is: http://www.schoenster.com/tests/smarty.php and here is the PHP script I wrote: (not that I used debugging!, that is a real nice helpful touch). compile_check = true; $smarty->template_dir = '.'; $smarty->debugging = true; $action = 'read'; $colors = array('red','blue','green','yellow'); foreach ( $colors as $color ) { $comments[] = array('nick'=>"nick $color",'comment'=>"comment $color"); } $smarty->assign('action',$action); $smarty->assign('comments',$comments); $smarty->display('smarty.html'); ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Smarty template question
I found my problem. Nick and comment were the wrong case, they should have been NICK and COMMENT. I can't believe I did that. Thanks for the help, Matt > -Original Message- > From: Peter J. Schoenster [mailto:[EMAIL PROTECTED]] > Sent: Saturday, September 28, 2002 5:25 PM > To: [EMAIL PROTECTED] > Cc: Matt Giddings > Subject: Re: [PHP] Smarty template question > > > > On 28 Sep 2002 at 15:48, Matt Giddings wrote: > > > 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: > > Matt, > > I suggest you break your code down to the simplest possible. Too many > factors in there for my taste. FWIW, I had to bang my head a few times > to get it and still have to verify my assumptions. For some reason I > took to Template::Toolkit rather fast but smarty is working fine for > me. > > Here are a few notes, but I'm fairly new to PHP so caution. > > First, totally unrelated to your question: > > > Function readComment( &$smarty, $bid ) { > > In Perl and in PHP I have my classes ONLY manipulate data and return > data to the handerl which then passes it off to what I call the > "viewer". In this way, in Perl for instance, I can use more than one > template system as I create a class for each template system and > manipulate the data as needed for that system. Works like a charm. In > this way you can use the code in your classes for manythings ... it's > not tied to your output. Also, now some might complain that this might > be slower or take more memory or whatever, but I do this with smarty: > > $data =& $g->run($com,$fid); > > $data is an array of data returned by my functions. > $data['content'] = $g->viewer->Merge($data,$template); > > print $g->viewer->Merge($data,'index.html'); > > So I *wrap* the content of pages into a page which pulls in > header/footer rather than having a header/footer in every page. > > Okay, back to your qeustion: > > > > while( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { > > $rowdata[$i] = $row; > > $i++; > > I don't think you need the $i. > > Are you sure you have data in $rowdata? > > Your use of section looks good to me. You've got those if statements. > Sure they are all true. > > I'm using section in lots of stuff and it's working fine. > > When I run into trouble I work from the most basic, the simplest and > then move up. > > Peter > > > > > --- > Incoming 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 > --- 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
RE: [PHP] Smarty template question
> -Original Message- > From: Peter J. Schoenster [mailto:[EMAIL PROTECTED]] > Sent: Saturday, September 28, 2002 5:25 PM > To: [EMAIL PROTECTED] > Cc: Matt Giddings > Subject: Re: [PHP] Smarty template question > > > > On 28 Sep 2002 at 15:48, Matt Giddings wrote: > > > 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: > > Matt, > > I suggest you break your code down to the simplest possible. Too many > factors in there for my taste. FWIW, I had to bang my head a few times > to get it and still have to verify my assumptions. For some reason I > took to Template::Toolkit rather fast but smarty is working fine for > me. > > Here are a few notes, but I'm fairly new to PHP so caution. > > First, totally unrelated to your question: > > > Function readComment( &$smarty, $bid ) { > > In Perl and in PHP I have my classes ONLY manipulate data and return > data to the handerl which then passes it off to what I call the > "viewer". In this way, in Perl for instance, I can use more than one > template system as I create a class for each template system and > manipulate the data as needed for that system. Works like a charm. In > this way you can use the code in your classes for manythings ... it's > not tied to your output. Also, now some might complain that this might > be slower or take more memory or whatever, but I do this with smarty: That does sound like a better and more logical approach. I think I'll incorporate that into my code. > $data =& $g->run($com,$fid); > > $data is an array of data returned by my functions. > $data['content'] = $g->viewer->Merge($data,$template); > > print $g->viewer->Merge($data,'index.html'); > > So I *wrap* the content of pages into a page which pulls in > header/footer rather than having a header/footer in every page. > > Okay, back to your qeustion: > > > > while( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { > > $rowdata[$i] = $row; > > $i++; > > I don't think you need the $i. I need the $i because I'm assigning the every row from the result into an array. > Are you sure you have data in $rowdata? Yup, $rowdata is filled with data, and the right data at that. :) > Your use of section looks good to me. You've got those if statements. > Sure they are all true. This one might be my downfall, I'll have to dig into this one a bit more. > I'm using section in lots of stuff and it's working fine. > > When I run into trouble I work from the most basic, the simplest and > then move up. > > Peter --- 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
Re: [PHP] Smarty template question
On 28 Sep 2002 at 15:48, Matt Giddings wrote: > 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: Matt, I suggest you break your code down to the simplest possible. Too many factors in there for my taste. FWIW, I had to bang my head a few times to get it and still have to verify my assumptions. For some reason I took to Template::Toolkit rather fast but smarty is working fine for me. Here are a few notes, but I'm fairly new to PHP so caution. First, totally unrelated to your question: > Function readComment( &$smarty, $bid ) { In Perl and in PHP I have my classes ONLY manipulate data and return data to the handerl which then passes it off to what I call the "viewer". In this way, in Perl for instance, I can use more than one template system as I create a class for each template system and manipulate the data as needed for that system. Works like a charm. In this way you can use the code in your classes for manythings ... it's not tied to your output. Also, now some might complain that this might be slower or take more memory or whatever, but I do this with smarty: $data =& $g->run($com,$fid); $data is an array of data returned by my functions. $data['content'] = $g->viewer->Merge($data,$template); print $g->viewer->Merge($data,'index.html'); So I *wrap* the content of pages into a page which pulls in header/footer rather than having a header/footer in every page. Okay, back to your qeustion: > while( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) ) { > $rowdata[$i] = $row; > $i++; I don't think you need the $i. Are you sure you have data in $rowdata? Your use of section looks good to me. You've got those if statements. Sure they are all true. I'm using section in lots of stuff and it's working fine. When I run into trouble I work from the most basic, the simplest and then move up. Peter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php