Jump to content
MakeWebGames

Recommended Posts

Posted

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.

Posted

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.

Posted
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 -.-

Posted

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.

Posted

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?

Posted

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.

Posted

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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...