Results 1 to 3 of 3

Thread: [RESOLVED] MySQL Query - Detect 2 numbers after =>

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Resolved [RESOLVED] MySQL Query - Detect 2 numbers after =>

    I have amount 200000000

    How i can make echo show: 20000 Gold coins 00 Silver coins 00 Bronze coins?
    Like: 20000,00,00 => put ',' mark two times to every two number?

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: MySQL Query - Detect 2 numbers after =>

    if the last four numbers are always the number of silver coins and bronze coins, and the remaining numbers denote how many gold coins there are, you can use the substr() function to break it up. I made this example:

    PHP Code:
    <?php
      
    //returns 20000,00,00
      
    echo convertCoins(200000000) . "\n\n";

      
    //returns 2,00,00
      
    echo convertCoins(20000) . "\n\n";

      
    //returns 2
      
    echo convertCoins(2) . "\n\n";
      
      function 
    convertCoins($n){
        
    $l strlen($n);
        
    $coins = array();
        
    //are there enough coins to show gold?
        
    if($l 4){
          
    //gold
          
    $coins[] = substr($n0, -4); //start at the beginning and go until the fourth-last character
        
    }
        
    //are there enough coins to show silver?
        
    if($l 2){
          
    //silver
          
    $coins[] = substr($n, -42); //start at the fourth-last character and stop 2 characters later
        
    }
        
    //always calculate bronze
        //bronze
        
    $coins[] = substr($n, -2);    //start at the second-last character and go until the end
        
        
    return implode($coins",");
      }

    ?>
    there could be many additions made to suit this to more specific needs, but it should give you a general idea. ask questions if you need help.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2008
    Location
    >> ( ҉ )
    Posts
    413

    Re: MySQL Query - Detect 2 numbers after =>

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width