TinyPortal

Development => Block Codes => Topic started by: TimUSA on October 04, 2007, 09:33:20 PM

Title: Help with code.
Post by: TimUSA on October 04, 2007, 09:33:20 PM
I have an article set up that I need conditionals on but I dont know how to do it.

the current code is:
<p>To obtain the AYC racing password please complete the <a href="http://vsk-ayc.totalh.com/index.php?page=70">Racing Fleet Application</a>.</p>

What I need to do is this:

if membergoup = Racing Fleet Member (Group #13)
then display this: The password for AYC events is xlr8 (lower case)

All others display the attached code

If anyone can help me with this, I would appreciate it.

TimUSA
Title: Re: Help with code.
Post by: jacortina on October 04, 2007, 10:22:28 PM
Try this:
global $scripturl, $user_info;

if (in_array(13, $user_info['groups'])
{
echo '<p>The password for AYC events is <b>xlr8</b> (lowercase)</p>';
}
else
{
echo '<p>To obtain the AYC racing password please complete the <a href="', $scripturl, '?page=70">Racing Fleet Application</a>.</p>';
}


This has to be in a php article (you may want to delete the one you have and create a new article using php).
Title: Re: Help with code.
Post by: TimUSA on October 04, 2007, 10:29:55 PM
Close I get this:
Title: Re: Help with code.
Post by: jacortina on October 04, 2007, 10:36:27 PM
Sorry. Missing a closing parenthesis:
global $scripturl, $user_info;

if (in_array(13, $user_info['groups']))
{
echo '<p>The password for AYC events is <b>xlr8</b> (lowercase)</p>';
}
else
{
echo '<p>To obtain the AYC racing password please complete the <a href="', $scripturl, '?page=70">Racing Fleet Application</a>.</p>';
}
Title: Re: Help with code.
Post by: TimUSA on October 04, 2007, 10:48:11 PM
This worked thanks!  :up:

if i change this code:
if (in_array(1, $user_info['groups']))

to include multiple groups:
if (in_array(1, 13, $user_info['groups']))

the code sends me to the "else" message
Title: Re: Help with code.
Post by: jacortina on October 04, 2007, 11:39:50 PM
Right. That function checks if the first argument is in the array which is the second argument.

You could do an OR for the two different values:
if (in_array(1, $user_info['groups']) || in_array(13, $user_info['groups']))

Or you can try the array_intersect() function and check for non-zero count:
if (count(array_intersect(array(1,13), $user_info['groups'])))

Title: Re: Help with code.
Post by: TimUSA on October 04, 2007, 11:43:17 PM
The second line worked fine. All done. Thanks for your help