Setting a maximum limit on a php/mysql result?

Discussion in 'PHP' started by RottNKorpse, Aug 5, 2007.

  1. #1
    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?
     
    RottNKorpse, Aug 5, 2007 IP
  2. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #2
    if ($var > 500) {
    $var = "500";
    }
    else {
    // code
    }
    
    PHP:
     
    crazyryan, Aug 5, 2007 IP
  3. Sohan

    Sohan Peon

    Messages:
    2,330
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    0
  4. lggmaster

    lggmaster Peon

    Messages:
    233
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Think he is referring to an actual number to be displayed on a page, not the count of records retrieved.
     
    lggmaster, Aug 5, 2007 IP
  5. bloodredxxx

    bloodredxxx Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $var = ($var>500?500:$var)
    PHP:
     
    bloodredxxx, Aug 6, 2007 IP