TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,992
  • Total Topics: 21,323
  • Online today: 557
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 361
  • Total: 361

Help with code.

Started by TimUSA, October 04, 2007, 09:33:20 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TimUSA

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

jacortina

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).

TimUSA


jacortina

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>';
}

TimUSA

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

jacortina

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'])))


TimUSA

The second line worked fine. All done. Thanks for your help

This website is proudly hosted on Crocweb Cloud Website Hosting.