help with SUM()

Discussion in 'PHP' started by SnoozZz, Jul 14, 2008.

  1. #1
    I'm creating something small for reps to follow up on sales.

    can somebody help me out with this

    the problem is $com commision on sales.
     
    SnoozZz, Jul 14, 2008 IP
  2. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't think you can use SUM in values, you can only use it when selecting fields like SELECT name, SUM(totals) *sums all the rows*

    You are probably better off doing it manually without the SUM()
     
    Mozzart, Jul 14, 2008 IP
  3. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I thought something like that, thanks

    will do it manual.
     
    SnoozZz, Jul 14, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Remove the quotations from around $com to make the function run, but I'm pretty sure it's not SUM you need! :eek:

    Good luck

    Dan
     
    Danltn, Jul 14, 2008 IP
  5. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #5
    hmm, i havent really tried this before, is an aggregate function like SUM possible to use during inserts?
    based on the query there's not even anything to SUM...

    damn, i just got dizzy
     
    serialCoder, Jul 14, 2008 IP
  6. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I'm pretty sure of it myself.

    all functions are working when I remove $com completely

    I just thought i'll make things a little easier for them. They can calculate their own commissions. The lazy buggers, sit around all day drinking coffe and work on my nerves. thatwill keep them busy.
     
    SnoozZz, Jul 14, 2008 IP
  7. clarky_y2k3

    clarky_y2k3 Well-Known Member

    Messages:
    114
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    108
    #7
    The SUM() function is for use within MySQL SELECT statements to aggregate a column. Furthermore, if you wished to use the function within the query you should have placed it within a string because SUM() is not a function within PHP:-

    
    $com = 'SUM(' . $amount * 0.25 . ')';
    
    PHP:
    You can calculate the commision by removing the SUM() function:-
    
    $com = $amount * 0.25;
    
    PHP:
     
    clarky_y2k3, Jul 14, 2008 IP
  8. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    its fine lough at me, :)

    at some stage in your life you were also still learning
     
    SnoozZz, Jul 14, 2008 IP
  9. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    thanks, I had this 'SUM' thing of exel in my head. clearly its not the same thing. Anybody who ever worked with exel will understand what I mean.

    this is how I learn
     
    SnoozZz, Jul 14, 2008 IP
  10. Mozzart

    Mozzart Peon

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I don't think anyone is laughing at you... and plus this is a php forum to help so we expect any kind of questions too, be it basic or advanced... it's all about learning :)
     
    Mozzart, Jul 14, 2008 IP
  11. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #11
    dude, i'm not laughing at you, were actually both learning, i just havent tried this query before so i got a little confused.

    anyways i apologize if that post somehow offended you, i did not mean it that way

    -cheers :)

     
    serialCoder, Jul 14, 2008 IP
  12. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I'm sitting here laughing at my own stupidity while i'm reading up about what SUM() does. I was way off. lol
     
    SnoozZz, Jul 14, 2008 IP
  13. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    no problem buddy, I'm an old man trying to learn new stuff, I don't take offence easily.. lets all laugh together and have a jolly time.
     
    SnoozZz, Jul 14, 2008 IP
  14. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #14
    yep, learning is a lot better when it is fun :)

     
    serialCoder, Jul 14, 2008 IP
  15. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Thanx Clarky that worked

    John will earn $32k commision July
    Mary will earn $26k

    I pay them tooo damn much
     
    SnoozZz, Jul 14, 2008 IP
  16. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    This works, I just wonder why the "PRO's" couldn't tell me this from the start.:D

    Just kidding. Thanks guys

    $com = $amount * 0.25;
    
    
    	$qry = "INSERT INTO data (date, rep, client, amount, com, status) VALUES ('$postdate', '$rep', '$client', '$amount', '$com', 'pending')";
    	$result = mysql_query($qry);
    	if($result) {
    		header("location: success.php");
    		exit();
    	}else {
    		die("Query failed");
    	}
    PHP:
     
    SnoozZz, Jul 14, 2008 IP