#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    99
    Rep Power
    2

    Number function !?


    Is there any function that will display a number as 60+ if the result its equal to 60 or higher but lower than 65 and if its egual to 65 or higher but lower than 70 to display 65+ ?
    I'm not talking about this number in particular, but in general for all numbers. I would like to count my article views like this not like 60,61,62,63 .... 70 x viewed.
    Like an interval from 5 to 5 and so on.
  2. #2
  3. Wiser? Not exactly.
    Devshed God 2nd Plane (6000 - 6499 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    6,265
    Rep Power
    4193
    No, there's nothing built in for that. You'll have to write one. Perhaps something like this:

    Code:
    function bucketize($num, $size){
        $overage = $num % $size;
        $base = $num - $overage;
        
        return $base . '+';
    }
    https://3v4l.org/fk35k

    The % operator does integer division between the two numbers and returns the remainder of that operation. You can use that to determine how far past your base number you've gone and then calculate that base number to show.
    Recycle your old CD's



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    99
    Rep Power
    2
    And how to integrate this? I'm kinda lost. My view variable is $row["times_viewed"]
  6. #4
  7. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,796
    Rep Power
    9646
    It's a function. Look at the code, understand how it works at a basic level, then put the function into your application and call it with the right arguments.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    99
    Rep Power
    2
    It gives me "missing argument 2" notification
  10. #6
  11. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,796
    Rep Power
    9646
    Then you need to call the function with the second argument.

    Or perhaps you should start first with a tutorial on how to use PHP?
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2016
    Location
    Cheshire, UK
    Posts
    89
    Rep Power
    72
    The method I use to round up or down to the nearest N (in your case N is 5) is

    PHP Code:
    floor($num/$N)*$N;     // to round down
    ceil($num/$N)*$N;      // to round up 
    So my function would be
    PHP Code:
       function nearestN($num$N$roundup=false)
       {
           return 
    $roundup ceil($num/$N)*$N floor($num/$N)*$N;
       }

        echo 
    nearestN(685);             //-> 65
        
    echo nearestN(6851);          //-> 70 
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2017
    Posts
    99
    Rep Power
    2
    Originally Posted by requinix
    Then you need to call the function with the second argument.

    Or perhaps you should start first with a tutorial on how to use PHP?
    yes please

IMN logo majestic logo threadwatch logo seochat tools logo