jimmyp3016 Posted April 11, 2007 Share Posted April 11, 2007 Hey Guys, Trying to figure this one out. I have this function below. function doCommision() { if ($user->jv == 'y') { define( "AFFILIATE_COMMISSION", 20 ); } else { define( "AFFILIATE_COMMISSION", 10 ); } } So basically if the user is a jv partner, the affiliate commisions are higher. I have a user that is a jv partner but it says he earns 10 when he should earn 20. I even echo'd the page for the jv variable and it says y. Users who jv is N show 10 which is the correct amount. Can you tell me what im doing wrong? Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 11, 2007 Share Posted April 11, 2007 I wouldn't store a string for simple comparison. I think it'd be more logical to use a boolean value. Too many things can go wrong with strings, such as extra whitespace or capital letters, etc, etc. If you can't change it to a boolean, then try checking strtolower(trim($user->jv)) rather than just $user->jv Quote Link to comment Share on other sites More sharing options...
jimmyp3016 Posted April 11, 2007 Author Share Posted April 11, 2007 Hey Glyde, Thanks for your quick response. I put your method in but its still showing 10 for jv = y I wonder why its doing that, when i echo the jv variable on the page it tells me y So in theory it should show 20 am i right? Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 11, 2007 Share Posted April 11, 2007 Has AFFILIATE_COMMISSION been defined anywhere else in your script? Try using a variable to store the commission instead of a constant. Quote Link to comment Share on other sites More sharing options...
jimmyp3016 Posted April 11, 2007 Author Share Posted April 11, 2007 its not defined anyplace else. How would I setup the variable instead? Quote Link to comment Share on other sites More sharing options...
redking Posted April 11, 2007 Share Posted April 11, 2007 I think the problem is that the $user object is a global variable and cannot be accessed from within the function. try either function doCommision() { global $user; if ($user->jv == 'y') { define( "AFFILIATE_COMMISSION", 20 ); } else { define( "AFFILIATE_COMMISSION", 10 ); } } or function doCommision($user) { if ($user->jv == 'y') { define( "AFFILIATE_COMMISSION", 20 ); } else { define( "AFFILIATE_COMMISSION", 10 ); } } Quote Link to comment Share on other sites More sharing options...
Waldir Posted April 11, 2007 Share Posted April 11, 2007 function doCommision() { global $user; if ($user->jv == 'y') { define( "AFFILIATE_COMMISSION", 20 ); } else { define( "AFFILIATE_COMMISSION", 10 ); } } Quote Link to comment Share on other sites More sharing options...
jimmyp3016 Posted April 11, 2007 Author Share Posted April 11, 2007 Thank you all for the help! This worked! function doCommision() { global $user; if ($user->jv == 'y') { define( "AFFILIATE_COMMISSION", 20 ); } else { define( "AFFILIATE_COMMISSION", 10 ); } } Problem Solved! Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 11, 2007 Share Posted April 11, 2007 Hah, didn't even catch that. I guess when he said he echoed $user->jv, he echoed it within the function, which is why I ruled that one out. Good catch redking. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.