Author Topic: TMPL_IF problem  (Read 832 times)

0 Members and 1 Guest are viewing this topic.

area32

  • Guest
TMPL_IF problem
on: Mon, 30. September 2002 - 10:29:34
Template:
Code: [Select]

html

head

titletmpl_var name=titel/title

/head



body

tmpl_var name=titel2



tmpl_if name=vragen

            tmpl_loop name=vraag_loop

            /tmpl_loop

tmpl_else

tmpl_var name=vraag

/tmpl_if



index.php
Code: [Select]

// Some include stuff and queries



$tmpl = new vlibTemplate'template/index.tpl';



$tmpl-setVar'titel', 'TEST';



$tmpl-setVar'titel2', 'Nieuwste onbeantwoorde vragen';



if$aantal_laatste_10_onbe = 0

$tmpl-setVar'vragen', 1;

$tmpl-setVar'vraag', 'Geen onbeantwoorde vragen.';



else

$tmpl-setDbLoop'vraag_loop', $result_laatste_10_onbe, 'MYSQL';



 while $rec_laatste_10_onbe = mysql_fetch_object$result_laatste_10_onbe

 $tekst = a href='vraag.php?id=$rec_laatste_10_onbe-id'$rec_laatste_10_onbe-vraag/abr
;

 $tmpl-setVar'vraag', $tekst;

  

 



 $tmpl-pparse;



If the table is empty he doesn't show 'Geen onbeantwoorde vragen.'
and if table isn't empty he doesn't show the loop.

plz help me. Thanks

releasedj

  • Guest
TMPL_IF problem
Reply #1 on: Mon, 30. September 2002 - 14:12:10
In your code, the first part of the if statement is:

Code: [Select]

if$aantal_laatste_10_onbe = 0

$tmpl-setVar'vragen', 1;

$tmpl-setVar'vraag', 'Geen onbeantwoorde vragen.';






.. as it is, this will always execute because of the '=' operator.
What I believe you should have is:
Code: [Select]

...

if$aantal_laatste_10_onbe == 0

...



I hope this solves your problem.

Regards,

Kelvin

Offline ClausVB

  • Administrator
  • Hero Member
  • *****
  • Posts: 566
    • Homepage: clausvb.de
TMPL_IF problem
Reply #2 on: Wed, 09. October 2002 - 09:41:18
Taken from

http://utvikler.start.no/code/php_coding_s...ard.html#ifthen

Quote
Always put the constant on the left hand side of an equality/inequality comparison. For example: 
if ( 6 == $errorNum ) ... 

One reason is that if you leave out one of the = signs, the parser will find the error for you. A second reason is that it puts the value you are looking for right up front where you can find it instead of buried at the end of your expression. It takes a little time to get used to this format, but then it really gets useful.


So this mistake wouldn't have happend in the first place.

I had problems with that, too. Now I try to always follow that rule.

CU
Claus