Kieran-R Posted January 6, 2011 Posted January 6, 2011 Hey Im having a little problem. Im trying to print something from the database. As its pretty hard to explain, Ill give an example; DB Data: $r['level']*4+5 I want it to print out the value. NOT $r['level']*4+5. Is there a solution, or a way that someone could tell me to overcome this problem? Thanks. Quote
Equinox Posted January 6, 2011 Posted January 6, 2011 Use echo or print.... Seems fairly obvious to me. Quote
Curt Posted January 6, 2011 Posted January 6, 2011 here is an example how to do this: $value=$ir['level']*5+4; echo " The value is $value "; remember to put () around the part of the equation you want to be executed first..such as: $value=$ir['level']*(5+4); This will make it so it adds 5+4 first then multiplies it by the users level. Hope that helps you. Quote
Dominion Posted January 6, 2011 Posted January 6, 2011 Hey Im having a little problem. Im trying to print something from the database. As its pretty hard to explain, Ill give an example; DB Data: $r['level']*4+5 I want it to print out the value. NOT $r['level']*4+5. Is there a solution, or a way that someone could tell me to overcome this problem? Thanks. I don't really get the problem it's just maths... That or it's a very bad example -.- Quote
Kieran-R Posted January 6, 2011 Author Posted January 6, 2011 No. The maths is in a field of the database, and I want to print out the total value. Not the sum... Just doing (example) echo $r['blah']; prints out the SUM. Not the total value. Quote
Dominion Posted January 6, 2011 Posted January 6, 2011 Eval() will work, however it's never really a good idea to use it. If you do you MUST make sure you only allow what you want (in this case numbers, and mathematical things like + etc...) Maybe something to split it up, and do it that way? Quote
Kieran-R Posted January 6, 2011 Author Posted January 6, 2011 Thanks Dominon. Never used eval before, but I'll do some reasearch on it.. Cheers Quote
Dominion Posted January 6, 2011 Posted January 6, 2011 It's rather dangerous to use unchecked. Look into things like explode (and other functions to split the string up) first. I always try to avoid using to due to it's rather obvious flaw of allow any php to run user input or not. As i said if you go that way make sure it's checked by something. Quote
Kieran-R Posted January 6, 2011 Author Posted January 6, 2011 For what I'm using it for, there is no user input involved in any of the values I will be using. So I'm sure I will be fine ;) Quote
Dayo Posted January 7, 2011 Posted January 7, 2011 So you are trying to do something like this? $lvl=$ir['level']; echo 'some text'.($lvl*5+4).'some text'; Quote
Kieran-R Posted January 7, 2011 Author Posted January 7, 2011 Noo..... The SUM is in the database... I want the total of that sum to be displayed. I dont want the sum in the PHP code Quote
Kieran-R Posted January 7, 2011 Author Posted January 7, 2011 OK. Heres what ive come up with. But now when it is echo'd, nothing is appearing: $chances=eval($chance['crimePERCFORM']); echo $chances; crimePERCFORM Data: (72+(($ir['level']/5)*10)); And as I said, nothing is printing out. Is there something im not doing right? Quote
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.