ti_nhatrang
06-14-2008, 06:12 PM
Hi all,
I just wanted to make an insert into a field that is already existed. There is a table called: ringroups with the field "annmsg" available. I basically want to insert my results into that field.
Here's what I have so far:
$result = mysql_query("SELECT * FROM grpnum_minutes WHERE RGID>0");
while ($row = mysql_fetch_assoc($result)) {
list ($CID) = mysql_fetch_row(mysql_query("SELECT CID FROM asterisk.incoming WHERE RGID='".$row['RGID']."'"));
list($billsec) = mysql_fetch_row(mysql_query("SELECT SUM(billsec) FROM asteriskcdrdb.cdr WHERE dst='".$row['grpnum']."' AND calldate > '".$row['lastbilldate']."'")) or die(mysql_error());
if ($billsec) {
mysql_query("UPDATE asterisk.grpnum_minutes SET totalused='".$billsec."' WHERE RGID='".$row['RGID']."'");
$row['totalused'] += $billsec;
$usedmins[$CID]['used'] += $billsec;
$usedmins[$CID]['RGID'][] = $row['RGID'];
}
//echo $row['RGID']." : Seconds: ".$billsec."\n";
}
foreach ($usedmins AS $key => $value) {
if ($value['used']) {
list ($CIDtotal) = mysql_fetch_row(mysql_query("SELECT total FROM asterisk.customerdb WHERE id='".$key."'"));
mysql_query("UPDATE asterisk.customerdb SET totalused='".$value['used']."' WHERE id='".$key."'");
//echo $key." --> "; print_r($value);
if ($CIDtotal <= $value['used']) {
foreach ($value['RGID'] AS $kvalue) {
mysql_query("UPDATE asterisk.incoming SET destination='ext-group,1,1' WHERE RGID='".$kvalue."'");
$changes = TRUE;
}
}
}
}
The above basically checks the total minutes used, and decide whether to change it to a different ext-group or what not...
I want to add something on top of what this script currently is doing... I want it to get the result of the minutes being checked, and if the minutes are positive, or less than the total minutes available, then I want that minute to be rounded off to a whole number, rather than 4.3 minutes = 4 minutes and 3 seconds... After rounding it off, I want to insert the 4 into the field into the "annmsg" in the table ringgroups.
Any kind of help would be greatly appreciated and thankful.
I just wanted to make an insert into a field that is already existed. There is a table called: ringroups with the field "annmsg" available. I basically want to insert my results into that field.
Here's what I have so far:
$result = mysql_query("SELECT * FROM grpnum_minutes WHERE RGID>0");
while ($row = mysql_fetch_assoc($result)) {
list ($CID) = mysql_fetch_row(mysql_query("SELECT CID FROM asterisk.incoming WHERE RGID='".$row['RGID']."'"));
list($billsec) = mysql_fetch_row(mysql_query("SELECT SUM(billsec) FROM asteriskcdrdb.cdr WHERE dst='".$row['grpnum']."' AND calldate > '".$row['lastbilldate']."'")) or die(mysql_error());
if ($billsec) {
mysql_query("UPDATE asterisk.grpnum_minutes SET totalused='".$billsec."' WHERE RGID='".$row['RGID']."'");
$row['totalused'] += $billsec;
$usedmins[$CID]['used'] += $billsec;
$usedmins[$CID]['RGID'][] = $row['RGID'];
}
//echo $row['RGID']." : Seconds: ".$billsec."\n";
}
foreach ($usedmins AS $key => $value) {
if ($value['used']) {
list ($CIDtotal) = mysql_fetch_row(mysql_query("SELECT total FROM asterisk.customerdb WHERE id='".$key."'"));
mysql_query("UPDATE asterisk.customerdb SET totalused='".$value['used']."' WHERE id='".$key."'");
//echo $key." --> "; print_r($value);
if ($CIDtotal <= $value['used']) {
foreach ($value['RGID'] AS $kvalue) {
mysql_query("UPDATE asterisk.incoming SET destination='ext-group,1,1' WHERE RGID='".$kvalue."'");
$changes = TRUE;
}
}
}
}
The above basically checks the total minutes used, and decide whether to change it to a different ext-group or what not...
I want to add something on top of what this script currently is doing... I want it to get the result of the minutes being checked, and if the minutes are positive, or less than the total minutes available, then I want that minute to be rounded off to a whole number, rather than 4.3 minutes = 4 minutes and 3 seconds... After rounding it off, I want to insert the 4 into the field into the "annmsg" in the table ringgroups.
Any kind of help would be greatly appreciated and thankful.
