News:

Wondering if this will always be free?  See why free is better.

Main Menu

Can't get post count variable to work

Started by darkNiGHTS, January 16, 2011, 12:01:27 PM

Previous topic - Next topic

darkNiGHTS

I'm trying to make a certain message appear to users in a certain board when they have less than 10 posts.  The board part I have working fine, but for some reason I can't get it to only show to people with less than 10 posts.

if ($user_info['posts'] < 10)

OR

if (in_array(4, $user_info['groups']))

Do not work.  I am running SMF 2.0 RC4 and would appreciate any help.  Thanks!


Illori

try posting in the coding board, you may get more replies. this board is more focused on the core of smf as it is without changes.

NanoSector

if ($user_info['posts'] <= 10)

Try that?
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

darkNiGHTS

Still same result. Everyone can view it regardless of their post count.

NanoSector

Quote from: darkNiGHTS on January 16, 2011, 01:10:57 PM
Still same result. Everyone can view it regardless of their post count.
Grawr...

if ($user_info['posts'] <= "10")
My Mods / Mod Builder - A tool to easily create mods / Blog
"I've heard from a reliable source that the Answer is 42. But, still no word on what the question is."

Arantor

Firstly, it's numeric, and a comparison against a string will have some interesting consequences, not least of which that "10" is considered less than "2", so there should be typecasting.

I'm willing to bet the problem is much more likely to be that $user_info isn't in scope. In which case...

if ($GLOBALS['user_info']['posts'] < 10)
  echo 'Message for those with 0 to 9 posts';

darkNiGHTS

My friend got it working using this:

if (array_intersect(array(4), $user_info['groups']))

Arantor

Interesting solution, definitely slower than using in_array(4, $user_info['groups']), and there should be no reason why array_intersect would work when in_array won't.

Advertisement: