Author Topic: Custom fields in if statements.  (Read 119 times)

GrimChaos

  • Newbie
  • *
  • Posts: 7
    • View Profile
Custom fields in if statements.
« on: January 30, 2012, 06:44:07 PM »
What i'm trying to do:

{Category:Field:3}: {Review:Field:3}
I am using field:3 as a text input so i can enter a username.

{Category:Field:4}: {Review:Field:4}
Field:4 is a star rating.

I'm trying to get an if statement so if Review:Field:3 is "N/A" then it will display "No Additional Reviews" but if it is something else it will display everything {Category:Field:3}: {Review:Field:3}  and {Category:Field:4}: {Review:Field:4}

I don't know what I'm doing, I tried searching the internet but it maybe a little over my head.

This is what I did but I sure it's completely wrong.
<?php
if ('{Review:Field:3}'=="N/A")
  echo "NO REVIEW";
else
  echo "{Category:Field:3}: {Review:Field:3}";
?>

Hope the post is clear enough.
Thanks

Also, if someone knows how to increase the number of stars to 10, I would be grateful as well.
Thanks again.

row1

  • SR Sole Developer
  • Hero Member
  • *****
  • Posts: 1192
    • View Profile
    • Sockware
Re: Custom fields in if statements.
« Reply #1 on: January 30, 2012, 08:09:53 PM »
Hi,

You are almost there.

Is this a review template? If so then something like this should work:
Code: [Select]
<?php
if ($vm->fields[2]=="N/A")
  echo 
"NO REVIEW";
else
  echo 
"{Category:Field:3}: {Review:Field:3}";
?>


This post might help further: http://simple-review.com/forum/index.php/topic,2427.msg4646.html#msg4646

If you don't want to use PHP then you could store {Review:Field:3} and {Category:Field:3}: {Review:Field:3} in hidden html divs and use JavaScript to check the value and decide which one should be displayed.

Hope that helps.
If you find Simple Review useful please submit a Review (http://extensions.joomla.org/extensions/communities-&-groupware/ratings-&-reviews/4725/details), your positive reviews will help keep me going!
Please also make suggestions and possible improvements in the forum!

GrimChaos

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Custom fields in if statements.
« Reply #2 on: January 31, 2012, 09:17:01 PM »
Thanks a lot!  Worked Great!

If wouldn't mind me asking, what is "$vm->fields[2]"?  and why is it '2'?
I just want to get a clearer picture, so hopefully won't have to ask again.


THANKS!!

row1

  • SR Sole Developer
  • Hero Member
  • *****
  • Posts: 1192
    • View Profile
    • Sockware
Re: Custom fields in if statements.
« Reply #3 on: February 01, 2012, 08:18:07 PM »
If wouldn't mind me asking, what is "$vm->fields[2]"?  and why is it '2'?

In programming lists are normally zero-based. So the first item is at index 0 and not 1 and the third item that you are interested in is at index 2.

If you are very keen: http://en.wikipedia.org/wiki/Zero-based_numbering
If you find Simple Review useful please submit a Review (http://extensions.joomla.org/extensions/communities-&-groupware/ratings-&-reviews/4725/details), your positive reviews will help keep me going!
Please also make suggestions and possible improvements in the forum!

GrimChaos

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Custom fields in if statements.
« Reply #4 on: February 04, 2012, 12:12:07 PM »
Thanks that clears it up.

Thanks again!