Jump to content

Recommended Posts

 

hey guys i need some help making a ratio function

 

i have a query that will return downloaded and uploaded values in raw form im using a byte converting function to convert the values into either b's, mb's ,gb's etc etc

 

i want to make a function that will compare the upload vs download and make a ratio IE.  1.23  or  0.45 and also i want to sort the order by the ratio value im not sure how to do that either

 

if anyone can help i would really appreciate it! 

 

thanks for the help!!

 

 

here is my current code

 

 

function byte_convert($bytes)
  {
    $symbol = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');

    $exp = 0;
    $converted_value = 0;
    if( $bytes > 0 )
    {
      $exp = floor( log($bytes)/log(1024) );
      $converted_value = ( $bytes/pow(1024,floor($exp)) );
    }

    return sprintf( '%.2f '.$symbol[$exp], $converted_value );
  }


            $ipbwi->DB->allow_sub_select=1;

                        $result = $ipbwi->DB->query("

                        SELECT u.downloaded,u.uploaded,u.uid
                        FROM users u
                        LIMIT 3    
                        ");


    while ($r = $ipbwi->DB->fetch_row($result)) {


          $downloaded = ''.byte_convert(&$r[downloaded]).'';
          $uploaded = ''.byte_convert(&$r[uploaded]).'';  
          
          $ratio = '';


   }

 

Link to comment
https://forums.phpfreaks.com/topic/146557-need-help-with-ratio-function/
Share on other sites

Take the bytes uploaded and divide it by the bytes downloaded.

 

This should give you the ratio you want.

 

                        SELECT u.downloaded,u.uploaded, (u.uploaded/u.downloaded) as ratio ,u.uid
                        FROM users u
                        ORDER BY ratio
                        LIMIT 3 

 

If that does not work for the order by, change it to

 

ORDER BY (u.uploaded/u.downloaded) 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.