Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

how to enter many "if" statements onto one module

how to enter many "if" statements onto one module

I saw in one recipe you made an array, but I am unclear on how to do this.

I have a module with this in it:

Code:

if ( 

JRequest::getVar('url') == 'search-results'
and JRequest::getVar('jr_brand') == 'canon'
) return 351;

I want to make many of those (up to 100 possibly) but do not want to make 100 modules.

How can I convert that so that it'll do this:

== 'fujitsu' return 352;
== 'hp' return 353;

etc, etc?

also, if possible to not require case sensitive that'd be nice.

thanks

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: how to enter many "if" statements onto one module

ok, you could do it this way that doesn't involve arrays, and converts everything to lower case. It's still very efficient:

if ( JRequest::getVar('url') == 'search-results' ) {
  $brand = strtolower(JRequest::getVar('jr_brand'));
  switch ($brand) {
    case "canon": return 351;
    case "fujitsu": return 352;
    case "hp": return 353;
    // add more as appropriate
  }
}

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: how to enter many "if" statements onto one module

awesome.  thanks!

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: how to enter many "if" statements onto one module

another question, what would syntax be if I wanted to change the = to LIKE?

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Re: how to enter many "if" statements onto one module

actually, nvm, i got it, thanks

thepiston
Junior Modder
ranks
useravatar
Offline
29 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10796
Newest User:
mokao3
Members Online:
0
Guests Online:
191

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked