2011-07-22 21 views
1

我在下面的代碼中得到這個錯誤,並且無法找出原因。我認爲它通過兩次$循環,但我不知道爲什麼。任何人都在意給我一個手校對?PHP注意:未定義的索引:致電/var/www/swvx/timedcdr2.php在線72

PHP公告:未定義指數:調用/var/www/swvx/timedcdr2.php上線72個

謝謝!

<? 
//to be polled every 30 seconds. should first get a list of accoutn IDs, then use them to get the CDR for the last day. 
//include switchvox libraries 
require_once("SwitchvoxRequest.php"); 

//define sql connection stuff 
$db_host = "host"; 
$db_user = "user"; 
$db_pass = "secret"; 
$db = "db"; 
$table_sr = "tblSalesReps"; 
$table_cd = "tblCallsMadeReceived_raw"; 
$link = mssql_connect($db_host, $db_user, $db_pass); 

//make sure we can connect 
if (!$link || !mssql_select_db($db, $link)) { 
     die('Unable to connect or select database!'); 
     } 

//define pbx connection stuff 
$sv_host = "url"; 
$sv_user = "user"; 
$sv_pass = "secret"; 

//query the salesrep table to find the account IDs available 
$acid_sql = "SELECT * FROM $table_sr WHERE [pbx_accountid] > 0"; 
$acid_res = mssql_query($acid_sql); 

//get and format the time and date as YYYY-MM-DD, format the time as HH:MM:SS 
$date = date('Y') . "-" . date('m') . "-" . date('d'); 
$time = date('H') . ":" . date('i') . ":" . date('s'); 

//take only the last hour of results, rather than an entire day 
$st_time = date('H')-1 . ":" . date('i') . ":" . date('s'); 

echo "<pre>"; 

while ($row = mssql_fetch_array($acid_res, MSSQL_ASSOC)) { 
     $req = new SwitchvoxRequest($sv_host, $sv_user, $sv_pass); 
     $reqpar = array 
       (
       'account_ids' => array 
         (
         'account_id' => array 
           (
           $row['pbx_accountid'] 
           ) 
         ), 
       'start_date' => array 
         (
         $date . " " . $st_time 
         ), 
       'end_date' => array 
         (
         $date . " " . $time 
         ), 
       'sort_field' => array 
         (
         ), 
       'sort_order' => array 
         (
         'DESC' 
         ) 
       ); 

     $res = $req -> send("switchvox.callLogs.search", $reqpar); 
     $result = $res->getResult(); 
     $calls = $result['calls']['total_items']; 
     print_r($calls); 
     print_r($row['pbx_accountid']); 
     echo "<br><br>"; 
     if($result['calls']['call']) { //<====LINE 72 ################################ 
       foreach($result['calls']['call'] as $call) { 
         $id = $call['id']; 
         //check to see if the call has already been logged 
         $id_sql = "SELECT * FROM $table_cd WHERE callID='$id'"; 
         $id_res = mssql_query($id_sql); 
         $exid = mssql_fetch_array($id_res, MSSQL_ASSOC); 

         if($exid['callID']) { 
           //print_r($exid); //uncomment to show duplicate results 
           } elseif (!$exid['callID']) { 
             //print_r($call); //uncomment to show new results 
             //varialbes to insert 
             $from = $call['from_number']; 
             $to = $call['to_number']; 
             $durat = $call['talk_duration']; 
             $start = $call['start_time']; 
             $callid = $call['id']; 
             $calltype = $call['origination']; 
             //set the proper values into extension/phonenumber 
             if($calltype == "outgoing") { 
               $extension = $from; 
               $phonenumber = $to; 
               } else { 
                 $extension = $to; 
                 $phonenumber = $from; 
               } 
             //insert the data into the table 
             $fi_sql = "INSERT INTO $table_cd (extension, phonenumber, calldatetime, duration, callID, calltype) VALUES ($extension, $phonenumber, '$start', '$durat', '$callid', '$calltype')"; 
             $fi_res = mssql_query($fi_sql); 
               } 
           } 
       } 
} 
?> 

edit- 它確實有效;它只是偶爾拋出該錯誤。至少我認爲它有效。我認爲它可能會達到pbx_accountid數組的最後結果,並且不再有更多結果?我要計算它的次數,看看它是否相符。

edit- 是的,每次運行時都會出現20次錯誤,並且有20個帳戶ID。如果沒有更多的呼叫索引,我該如何強制停止它?

+0

很好的工作與通知上運行。使代碼更清潔:up: – iLLin

回答

3

更改此

if($result['calls']['call']) { //<====LINE 72 ################################ 

對此

if(isset($result['calls']['call'])) { //<====LINE 72 ################################ 

該通知意味着你正在讀一個不存在的變量。你這樣做是爲了檢查變量是否存在。有一個函數可以檢查變量是否存在,但不嘗試讀取它,isset

+0

太棒了!錯誤消失了。我會讓這個明天整天運行,看看它是否會產生任何結果。 – lorsungcu

+0

偉大:)請將我的答案標記爲已接受。您的個人資料中有一個鏈接http://thedrift.co/,但這對我來說不起作用,僅供參考。我想查看您的網站。 –

+0

謝謝,主要用於電子郵件。我有一天會得到一個網站。目前內容很難實現。 – lorsungcu

相關問題