SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2003
    Location
    nola
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to set 'as' decimal(5,2)

    Im making an affiliate program script and I need to take the total commission earned and divide by the number of clicks to find the EPC (earnings per click).

    The problem is $EPC prints $0.33333333333333 ($1.00 earnings / 3 clicks)

    My question is: How can I make the 'AS epc' in the query a decimal(5,2) so it will print just $0.33



    PHP Code:

    $sqlEPC 
    "SELECT sum(totalcomm), sum(click), (sum(totalcomm) / sum(click)) AS epc FROM transactions where OFID = $row[OFID] AND AFID = '{$_REQUEST['AFID']}' Group BY AFID ";

    $resultEPC mysql_query($sqlEPC$conn);   
    if (!
    $resultEPC) { 
      echo(
    "<p>Error performing query: " mysql_error() . "</p>"); 
      exit(); } else {


    while (
    $EPCrow mysql_fetch_array($resultEPCMYSQL_ASSOC)) { 
    $EPC $EPCrow[epc];
    }
    //end while
    }//end else 

  2. #2
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    round(0.33333, 2);

    output = o.33

    note: if value is 0.335, output will be 0.34

    you can thus choose ceil() or floor() function to cater for your needs.

  3. #3
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or
    PHP Code:
      number_format($EPC2); 


Bookmarks

Posting Permissions

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