Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2005
    Posts
    694

    php or mysql sum?

    Hello All,

    I am trying to pull out the amount of mins and total it up but having some issues, not sure if it's my php or mysql, but please help if you could:

    Code:
    $vmins_db = mysql_query("select SUM(billsec) as total_sec,calldate from asteriskcdrdb.cdr where dst='600' order by calldate desc limit 15");
    	while($vmins = mysql_fetch_array($vmins_db)) {
    	
    	$sum = $vmins[total_sec];
    	
    	echo "call dates: $vmins[calldate] - Talktime: $vmins[billsec]"; 
    
    }
    echo "$sum";
    ?>
    thanks all for your help.

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Depends on what you're trying to do, but at a guess you probably want:
    Code:
    select SUM(billsec) as total_sec,calldate from asteriskcdrdb.cdr where dst='600' GROUP BY calldate order by calldate desc limit 15
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Nov 2006
    Location
    College Station, TX
    Posts
    185
    If you post an SQL function, could you please describe what you're trying to get? The code's very reasonable, we can see how you're answering the question, we just also need to know what question was asked in the first place. It would also help to know what other columns are in the table.

    In this case, the query that foobic proposed would get you the number of billable seconds per day. You could change to grouping by the customer ID to get the number of calls per day per customer.

  4. #4
    Join Date
    Apr 2005
    Posts
    694
    Thanks all for your help.

    Foobic is correct and I needed just like that, however I can group by customers and calldate as well?

  5. #5
    Join Date
    Aug 2004
    Location
    Shanghai
    Posts
    1,449
    Yup, just use "group by x,y" instead of just "group by x"
    GPLHost:>_ open source hosting worldwide (I'm founder, CEO & official Debian Developer)
    Servers & our leading control panel and our Xen VPS hosting, which are already included in Debian and Ubuntu
    Available in: Kuala Lumpur, Singapore, Sydney, Seattle, Atlanta, Paris, London, Barcelona, Zurich, Israel

Posting Permissions

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