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

Smarty logic problem

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Tue Feb 08, 2005 4:41 am    Post subject: Smarty logic problem Reply with quote

I have the following bit of code:
if($result->numRows() == 0) {
$smarty->assign('bEvergreenDonation', false);
} else {
while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$txtEvergreenDonation[] = $row['fPledgeAmount'] . " started on " . $row['dtStart'] . " and will expire on " . $row['dtEnd'];
}
$smarty->assign('bEvergreenDonation', true);
$smarty->assign("txtEvergreenDonation", $txtEvergreenDonation);

}
In the case where $result->numRows() is zero (0) , bEvergreenDonation should be assigned the value of false. However, it is consistently assigned the value of "True" and I cant figure out why. Have I missed something here?

Here is my template code also:
{if bEvergreenDonation}
<p>{$persVal.txtSalutation} {$persVal.txtFirstNames} {$persVal.txtLastName} is an evergreen donor. The current pledge of ${$txtEvergreenDonation[0]}.
Click <INPUT TYPE="button" Value="Evergreen Donation" onClick="showEvergreenWindow('{$persVal.nId}', '{$persVal.txtFirstNames} {$persVal.txtLastName}', 'Edit')"> to edit the pledge.</p>
{else}
<p>{$persVal.txtSalutation} {$persVal.txtFirstNames} {$persVal.txtLastName} is not an evergreen donor. If the voter wishes to become an evergreen donor
click the button <INPUT TYPE="button" Value="Evergreen Donation" onClick="showEvergreenWindow('{$persVal.nId}', '{$persVal.txtFirstNames} {$persVal.txtLastName}', 'Add'"> and complete the form.
</p>
{/if}

Other than this cockup, the thing works as it should.

Rick
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue Feb 08, 2005 8:21 am    Post subject: Reply with quote

>>> $smarty->assign('bEvergreenDonation', true); <<<

you are doing this *after* the if.
this belongs into the else-part.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Tue Feb 08, 2005 3:27 pm    Post subject: Reply with quote

It is after the else part. Are you saying that the statement $smarty->assign('bEvergreenDonation', false); is not required?

Rick
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue Feb 08, 2005 3:58 pm    Post subject: Reply with quote

my fault: i didn't recognize that "$smarty->assign('bEvergreenDonation', true);" is *inside* the else part of your example, because the lack of any indentiation.
forget it.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Tue Feb 08, 2005 4:20 pm    Post subject: Reply with quote

Other than that, do you see any fault in the logic as presented. I discovered another bit of code that is exhibiting the same behaviour.

Rick
Back to top
View user's profile Send private message
messju
Administrator


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

PostPosted: Tue Feb 08, 2005 4:50 pm    Post subject: Reply with quote

i just noticed:

{if bEvergreenDonation} is always true, it's like {if "bEvergreenDonation"}.
you want {if $bEvergreenDonation}.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ricklach
Smarty Regular


Joined: 27 Aug 2004
Posts: 39

PostPosted: Tue Feb 08, 2005 8:56 pm    Post subject: Reply with quote

That did the trick. You can't imagine how long I looked at it only to miss the obvious. A second opinion is always in order. Thanks,

Rick
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons 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