PHP Notice: Undefined index: call in /var/www/swvx/timedcdr2.php on line 72
<p>I am getting this error on the following code, and cant figure out why.  I think it is looping through each $call twice, but I dont know why.  Anyone care to give me a hand proofreading?</p>

<p>PHP Notice:  Undefined index: call in /var/www/swvx/timedcdr2.php on line 72</p>

<p>Thanks!</p>

<pre><code>&lt;?
//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] &gt; 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 "&lt;pre&gt;";

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

        $res = $req -&gt; send("switchvox.callLogs.search", $reqpar);
        $result = $res-&gt;getResult();
        $calls = $result['calls']['total_items'];
        print_r($calls);
        print_r($row['pbx_accountid']);
        echo "&lt;br&gt;&lt;br&gt;";
        if($result['calls']['call']) {   //&lt;====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);
                                                }
                                }
                }
}
?&gt;
</code></pre>

<p>edit-
It does work; it just throws that error once in a while.  At least I tihnk it works.  I assume that it maybe gets to the last result of the pbx_accountid array and theres no more?  I am going to count the number of times it goes, and see if it corresponds.</p>

<p>edit-
yes, there are 20 occurences of the error every time it's run, and there are 20 account IDs.  How do I force it to stop if there are no more call indexes?</p>
