icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.
Old August 16th, 2007, 6:44 PM   #1 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
Even Numbers

I'm back again, and this is for a modification I plan to make for my forumhome of my vBulletin software.

I've got it all mapped, except for one thing. Is there a way that I can have PHP check if, let's say, $var is a even number? (the variable value is a number).

The variable will be using the forumid numbers, and thus I want it to find every even number forumid. I know the basic layout, but I need it to check is the id is an even number or not.

I know how to do the layout of the coding, just need that php function.

Thanks in advance!
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 16th, 2007, 6:55 PM   #2 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,227 posts
Gave thanks: 18
Thanked 86 times
Use the "%" modulus operator.. (remainder of $a divided by 2)
PHP Code:
function is_even($a)
{
  if ((
$a 2) == 0) {
    return 
true;
  } else {
    return 
false;
  }

MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks MarkRH for this great post!
GamingHybrid (August 16th, 2007)
Old August 16th, 2007, 6:59 PM   #3 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
so, I should replace $a with the variable I'm trying to check if its number is an even number, right?

Thank you MarkRH, you've been a great help like always
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 16th, 2007, 7:05 PM   #4 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,227 posts
Gave thanks: 18
Thanked 86 times
Well, if you do an inline comparision, yes. Or you just call the function like:

if (is_even($myvariable)) then do whatever cause it's even.

Otherwise.. do:

if (($myvariable % 2) == 0) then do whatever cause it's even.
MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks MarkRH for this great post!
GamingHybrid (August 16th, 2007)
Old August 16th, 2007, 7:25 PM   #5 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
PHP Code:
function is_even($forum[forumid])
{
  if ((
$forum[forumid] % 2) == 0) {
    return 
true;
    
$forumbit_align 'style="flost:right"';
  } else {
    return 
false;
  }

Using that, it comes up with:

Parse error: syntax error, unexpected '[', expecting ')' in /home/gaminghy/public_html/forums/index.php(63) : eval()'d code on line 3
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 16th, 2007, 7:28 PM   #6 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
Is the above my variable causing the issue? If so, I know how to fix... actually, I'll try it now...
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 16th, 2007, 7:54 PM   #7 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
i found the issue, just trying to make it work with vBulletin now. thanks Mark!
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old August 16th, 2007, 7:56 PM   #8 (permalink)
Race Surpass
Super #1
 
MarkRH's Avatar
 
Joined in Jul 2006
Lives in Oklahoma City, OK
Hosted on sh102
1,227 posts
Gave thanks: 18
Thanked 86 times
No.. don't change that is_even function at all. All it's meant to do is evaluate if a variable passed to it is even or not and return true or false.

In your main code:
PHP Code:
if (is_even($forum['forumid'])) { 
    
$forumbit_align 'style="float:right"'
  } else { 
    do 
whatever because its odd 
  

or do not use the function at all and do:
PHP Code:
if (($forum['forumid'] % 2) == 0) { 
    
$forumbit_align 'style="float:right"'
  } else { 
    do 
whatever because its odd 
  

MarkRH is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
This user thanks MarkRH for this great post!
GamingHybrid (August 16th, 2007)
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On