Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with calculating figures

    Hi Guys,

    Can anyone possibly help with with this?

    I have designed a basic affiliate program script. Affiliate Commissions are a flat fee of $50. I am trying to code the page that spits out the affiliate earnings for each month.

    When we have verified the order we use a script to set a column (status) in the order table to 'approved', I am not currently putting in the commission amount ($50) into the Db as I was hoping to just count the rows where status = 'approved' and do some math.

    Only prob is, I dont know how to do it !!

    I have been trying to use this code below as a starter to build my query, at the moment its just counting the rows:

    PHP Code:
    $month 1;
    while(
    $month 13){

     while(
    $month 13){
    $mon $month;
    if (
    $month 10)
    $mon "0".$month;

    // make the query to get the postings
    $query1 "SELECT Affiliate_ID, Status FROM orders WHERE Affiliate_ID=$_SESSION[affiliate_id] AND Status=approved"

    // run the query
    $result1 = @mysql_query ($query1) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " $query1 "<br />\nError: (" mysql_errno() . ") " mysql_error());

    // get the number of rows
    $num1 mysql_num_rows($result1);

    echo 
    "<td align=\"center\" class=\"row1\"><span class=\"link\">$num1</span></td>";

    $month++;

      } 
    For example... If there were 2 entries in the orders table for affiliate_id 1 that had the value of 'approved' in the status column. I would like to calculate and echo 2x$50



    Any help would be greatly appreciated.
    Last edited by adammc; 09-01-2006 at 07:02 AM.

  • #2
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoo Hoo, I worked it out!


    PHP Code:
    $month 1;
    while(
    $month 13){

     while(
    $month 13){
    $mon $month;
    if (
    $month 10)
    $mon "0".$month;

    // make the query to get the postings
    $query1 "SELECT Affiliate_ID, Status FROM orders WHERE Affiliate_ID='web$_SESSION[affiliate_id]' AND Order_Result='approved' AND Inquiry_Date LIKE '2006-$mon%'"

    // run the query
    $result1 = @mysql_query ($query1) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " $query1 "<br />\nError: (" mysql_errno() . ") " mysql_error());

    // get the number of rows
    $num1 mysql_num_rows($result1);

    $amount$num1 50;

    echo 
    "<td align=\"center\" class=\"row1\"><span class=\"link\">$amount</span></td>";

    $month++;

      } 

    Is my query correct? I mean can I use 2 'AND' Statements?

  • #3
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You could do the math in the query
    Code:
    SELECT COUNT(Affiliate_ID) * 50 AS amount FROM orders WHERE Affiliate_ID='web$_SESSION[affiliate_id]' AND Order_Result='approved' AND Inquiry_Date LIKE '2006-$mon%'
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

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