Jump to content

Setting a maximum limit on a php/mysql result?


RottNKorpse

Recommended Posts

Hi,

I have a question I can't seem to figure out on my own using tutorials or documentations so I was hoping someone here could help me out. Here is my problem.

 

I am using PHP and MySQL to do this script. I want to have a table that contains only numbers for data and then add them all up as a result to display and that I have accomplished with no problem and then I want to display a percentage of that number to the public however that also I have accomplished with no problem using round()...

 

The problem is I am trying to set a maximum number that it displays.

 

I want it to display 1-500 no matter what the number is or the decimal it may have is provided it doesnt exceed 500 but once it does I want it to display 500 as the limit so even if it is say 674 I want it to only display 500.

 

How would I go about doing this?

 

The sql I am using for the adding is SELECT SUM which works just fine and I am using round( $total_number *.15, 2) to display the percentage number of 15%. But not I am completely at a loss at what to do for the maximum number thing so any ideas?

thank you for trying to help but I wanted the limit to be set after the sql is called because there would be two values on one sql and if I limit one it would do both...Anyway, I figured it out...just a simple if statement was all I needed...silly me.

 

if ($variable > 500) {
echo "this";
} else {
echo "that";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.