aphex_ Posted May 16, 2006 Share Posted May 16, 2006 I am attempting to make an operator in an if conditionala variable like so:$x=1;$y=2;$operator='!=';if ($x $operator $y) {echo "Not equal!\n";}But obviously that doesnt work.Does anyone know if something like this is achievable and how? [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Any help would be appreciated.Thanks,Aphex_ Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 16, 2006 Share Posted May 16, 2006 You could look at using the [a href=\"http://www.php.net/eval\" target=\"_blank\"]eval()[/a] function.Tell us in more detail why you want to do this and we might be able to suggest an alternative method.Ken Quote Link to comment Share on other sites More sharing options...
aphex_ Posted May 17, 2006 Author Share Posted May 17, 2006 Well, I will be storing the operators in database fields in a table.This table will also store the column name that is being checkedand the variable it is being compared with.Basically, this will allow end users to write rules so that iftext fields meet certain conditions they are notified by email.A real world example would be so that if a car sale is made forover $50,000 the boss is notified.In this case the column name might be sale_amount and the comparison variable $50,000. The operator database fieldobviously would be '>=';So when a new row is injected in the database recording a car sale,the rules table is checked, and if the sale amount is over 50k, the boss is notified. Quote Link to comment Share on other sites More sharing options...
aphex_ Posted May 17, 2006 Author Share Posted May 17, 2006 I just wanted to thank the last responder for their suggestion to use the eval() function.I have managed to get it partially working with this and that has been the bestanswer anyone has given me to this question so far.-Aphex Quote Link to comment Share on other sites More sharing options...
alpine Posted May 17, 2006 Share Posted May 17, 2006 if you still have problems (working partially) you could post your current code to get further help Quote Link to comment Share on other sites More sharing options...
aphex_ Posted May 17, 2006 Author Share Posted May 17, 2006 Here is what I am doing and it is working -$x='somestring';$y='someotherstring';$operator = '==';$condition="if ($x $operator $y) {echo "We gotta match!\n";}";eval("$condition");Thanks Again! Quote Link to comment Share on other sites More sharing options...
toplay Posted May 17, 2006 Share Posted May 17, 2006 [!--quoteo(post=374566:date=May 16 2006, 11:09 PM:name=aphex_)--][div class=\'quotetop\']QUOTE(aphex_ @ May 16 2006, 11:09 PM) [snapback]374566[/snapback][/div][div class=\'quotemain\'][!--quotec--]Here is what I am doing and it is working -$x='somestring';$y='someotherstring';$operator = '==';$condition="if ($x $operator $y) {echo "We gotta match!\n";}";eval("$condition");Thanks Again![/quote]I think you meant:$condition="if ($x $operator $y) {echo \"We gotta match!\n\";}";otherwise you'd get a syntax error. 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.