|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ricklach Smarty Regular
Joined: 27 Aug 2004 Posts: 39
|
Posted: Tue Feb 08, 2005 4:41 am Post subject: Smarty logic problem |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Feb 08, 2005 8:21 am Post subject: |
|
|
>>> $smarty->assign('bEvergreenDonation', true); <<<
you are doing this *after* the if.
this belongs into the else-part. |
|
Back to top |
|
ricklach Smarty Regular
Joined: 27 Aug 2004 Posts: 39
|
Posted: Tue Feb 08, 2005 3:27 pm Post subject: |
|
|
It is after the else part. Are you saying that the statement $smarty->assign('bEvergreenDonation', false); is not required?
Rick |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Feb 08, 2005 3:58 pm Post subject: |
|
|
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 |
|
ricklach Smarty Regular
Joined: 27 Aug 2004 Posts: 39
|
Posted: Tue Feb 08, 2005 4:20 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Feb 08, 2005 4:50 pm Post subject: |
|
|
i just noticed:
{if bEvergreenDonation} is always true, it's like {if "bEvergreenDonation"}.
you want {if $bEvergreenDonation}. |
|
Back to top |
|
ricklach Smarty Regular
Joined: 27 Aug 2004 Posts: 39
|
Posted: Tue Feb 08, 2005 8:56 pm Post subject: |
|
|
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 |
|
|
|
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
|