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?
Setting a maximum limit on a php/mysql result?
Moderator: General Moderators
-
RottNKorpse
- Forum Newbie
- Posts: 10
- Joined: Sun Aug 05, 2007 3:04 pm
Code: Select all
SELECT
IF (number > 500, 500, number)
FROM tableThere are 10 types of people in this world, those who understand binary and those who don't
- iknownothing
- Forum Contributor
- Posts: 337
- Joined: Sun Dec 17, 2006 11:53 pm
- Location: Sunshine Coast, Australia
The Following can be used, so it counts up 500 every page..(If maybe you wanted to do that)
URL = "http:www.yousite.com/index.php?pageID=1" (First Page)
URL = "http:www.yousite.com/index.php?pageID=1" (First Page)
Code: Select all
$pageID = $_GET['pageID'];
$limitLow = ($pageID * 500) - 500; //Page 1 (0)
$limitHigh = $pageID * 500; //Page 1 (500)
$sql = "SELECT * FROM your_table LIMIT $limitLow, $limitHigh";-
RottNKorpse
- Forum Newbie
- Posts: 10
- Joined: Sun Aug 05, 2007 3:04 pm
thank you for your assistance...although that didn't exactly solve my problem it did lead me in the direction that I needed to be. I realized that a simple if statement would do what I wanted...silly me.VladSun wrote:Code: Select all
SELECT IF (number > 500, 500, number) FROM table
Code: Select all
if ($variable > 500) {
echo "this";
} else {
echo "that";
}Although this isn't what I was looking for it will actually come in handy because I do need this for another project so thank you for this.iknownothing wrote:The Following can be used, so it counts up 500 every page..(If maybe you wanted to do that)
URL = "http:www.yousite.com/index.php?pageID=1" (First Page)
Code: Select all
$pageID = $_GET['pageID']; $limitLow = ($pageID * 500) - 500; //Page 1 (0) $limitHigh = $pageID * 500; //Page 1 (500) $sql = "SELECT * FROM your_table LIMIT $limitLow, $limitHigh";