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? Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/ 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 Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227277 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? Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227279 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. Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227281 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? Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227282 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 ); } } Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227284 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 ); } } Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227285 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! Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227287 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. Link to comment https://forums.phpfreaks.com/topic/46659-solved-help-with-snipit/#findComment-227289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.