RottNKorpse Posted August 5, 2007 Share Posted August 5, 2007 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? Link to comment https://forums.phpfreaks.com/topic/63452-setting-a-maximum-limit-on-a-phpmysql-result/ Share on other sites More sharing options...
Barand Posted August 5, 2007 Share Posted August 5, 2007 Do you mean SELECT colname1, SUM(colname2) as total GROUP BY colname1 HAVING total <= 500 Link to comment https://forums.phpfreaks.com/topic/63452-setting-a-maximum-limit-on-a-phpmysql-result/#findComment-316212 Share on other sites More sharing options...
RottNKorpse Posted August 6, 2007 Author Share Posted August 6, 2007 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"; } Link to comment https://forums.phpfreaks.com/topic/63452-setting-a-maximum-limit-on-a-phpmysql-result/#findComment-316719 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.