Support Forums

How to compare variable

This is a discussion on How to compare variable within the Modules / Plugins / Modifications forums, part of the Developer Forums category; Hi, I created a checkbox "extrafields" name "Prefered Payment" with 9 options: 1 Cash 2 Check 3 Cash On Delivery ...


Go Back   68 Classifieds Forums > Developer Forums > Modules / Plugins / Modifications

Reply
 
Thread Tools Display Modes
Old 04-13-2009, 05:08 PM   #1
Customer
 
hel68c's Avatar
 
Join Date: Jun 2008
Location: Canada, Quebec
Posts: 289
Rep Power: 22
hel68c is just really nice hel68c is just really nice
Default How to compare variable

Hi,

I created a checkbox "extrafields" name "Prefered Payment" with 9 options:

1 Cash
2 Check
3 Cash On Delivery (COD)
4 Money Order/Cashiers Check
5 PayPal
6 Visa/MasterCard
7 American Express
8 Discover
9 Other (explain in your ad description)

In Viewlisting2.tpl I need to compare the option to know wich one as been choose from the client.

Eg: if client choose 1 Cash and 5 Paypal

it will display "Prefered Payment: Cash, Paypal"

in viewlisting2.tpl I write this code:

{if $extrafields.16.value.0|truncate:1:""=="1"
Cash,
{elseif $extrafields.16.value.0|truncate:1:""=="2"}
Check,
{elseif $extrafields.16.value.0|truncate:1:""=="3"}
Cash on Delivery,
{/if}

and so on...

{if $extrafields.16.value.1|truncate:1:""=="1"
Cash,
{elseif $extrafields.16.value.1|truncate:1:""=="2"}
Check,
{elseif $extrafields.16.value.1|truncate:1:""=="3"}
Cash on Delivery,
{/if}

and so on up to 9...

That's a lot of COMPARISON.

Do you know a method that is more effective?
__________________
Serge
HobbyClassified.com
V4.08 Developper, Module installed (CIV Scam Filter, Maffo Location System, Maffo News,Youtube, Seller Store)
hel68c is offline   Reply With Quote
Old 04-13-2009, 05:43 PM   #2
Developer & Moderator
 
 
Join Date: Jan 2007
Location: Pennsylvania, USA
Posts: 2,311
Rep Power: 69
Mike-N-Tosh is just really nice Mike-N-Tosh is just really nice
Default

I'm not sure I'm understanding why you feel that you need to add all that logic. For each checkbox that is checked, that is added to the field, so when the field is displayed as you showed in your posting, it will show all of the items that were checked.

What exactly is it that you are trying to accomplish?
__________________
Mike-N-Tosh
IndianaPC.org - A community website (v3.1.10 Developer - heavily modified & used as the CMS)
Sandbox [localhost(v3.1.10, v4.0.9, 4.1.10,4.2,5.0)] for development and customization
Visit My blog: reviews, tips, tricks, tutorials and my store with Templates, Mods & Docs
Web Hosting | Web Design & Development | 68 Classifieds Customizations
I am not a 68C employee, just a user and try to help out
Mike-N-Tosh is offline   Reply With Quote
Old 04-13-2009, 05:52 PM   #3
Customer
 
hel68c's Avatar
 
Join Date: Jun 2008
Location: Canada, Quebec
Posts: 289
Rep Power: 22
hel68c is just really nice hel68c is just really nice
Default

Hi Mike,

I need to compare this field because I used two languages. So all depend on the user choice in french or english.

in english the option fields are:

1 Cash
2 Check
3 Cash On Delivery (COD)
4 Money Order/Cashiers Check
5 PayPal
6 Visa/MasterCard
7 American Express
8 Discover
9 Other (explain in your ad description)

in french the option fields are:

1 Argent comptant
2 Ch�que
3 Paiement sur livraison
4 Mandat-Poste/Traite banquaire
5 PayPal
6 Visa/MasterCard
7 American Express
8 Discover
9 Autre (pr�ciser dans la description)

so I compare with the first letter (number)


I do not know if I well explain my application?
__________________
Serge
HobbyClassified.com
V4.08 Developper, Module installed (CIV Scam Filter, Maffo Location System, Maffo News,Youtube, Seller Store)
hel68c is offline   Reply With Quote
Old 04-13-2009, 06:35 PM   #4
curmudgeon
 
Join Date: Mar 2006
Posts: 5,413
Rep Power: 138
Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light Lhotch is a glorious beacon of light
Default

use in_array on $extrafields.16.value
__________________
Larry

Knowledge learned is more valuable than knowledge given.
Lhotch is offline   Reply With Quote
Old 04-14-2009, 04:16 PM   #5
Customer
 
hel68c's Avatar
 
Join Date: Jun 2008
Location: Canada, Quebec
Posts: 289
Rep Power: 22
hel68c is just really nice hel68c is just really nice
Default

Hi Lhotch,

I tried this code on my template but it doesn't work.

Quote:
{if in_array($extrafields.16.value)=="Cash"}
Cash,
{/if}
Do I have to do inside a foreach?
__________________
Serge
HobbyClassified.com
V4.08 Developper, Module installed (CIV Scam Filter, Maffo Location System, Maffo News,Youtube, Seller Store)
hel68c is offline   Reply With Quote
Old 04-14-2009, 04:52 PM   #6
Customer
 
hel68c's Avatar
 
Join Date: Jun 2008
Location: Canada, Quebec
Posts: 289
Rep Power: 22
hel68c is just really nice hel68c is just really nice
Default

Ok I find it

the Code is

Quote:
{if in_array("Check",$extrafields.16.value)}
Check,
{/if}
Thanks for your help
__________________
Serge
HobbyClassified.com
V4.08 Developper, Module installed (CIV Scam Filter, Maffo Location System, Maffo News,Youtube, Seller Store)
hel68c is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
category variable seymourjames Modules / Plugins / Modifications 5 08-26-2008 11:24 AM
Compare products: Geodesic vs 68 jds41979 Pre Sales Questions 5 05-08-2008 10:58 AM
$Body Variable? kampbell Templates, HTML, CSS, and Design Help 2 08-26-2007 11:41 AM


All times are GMT -4. The time now is 04:44 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0