wsantos Posted July 31, 2007 Share Posted July 31, 2007 First question: I'm having trouble populating the $asteriskcdrdataarr table Second question: Is there any better algorithm to make this query faster I put this in spaghetti code so we can discuss this line by line. Help is much appreciated. // Connect to CDR Table $conCDR = mysql_connect("10.20.41.21","user","pwd"); if(!$conCDR) { die('Could not connect: ' . mysql_error()); } $CDR = mysql_select_db("cdr",$conCDR); // Trying to get all activity for that given date from CDR and asteriskcdr. $qryCDR = "SELECT uniqueid,clid from cdr where clid like '%" . $Group . " G%' and cdr.start >= '" . $startdate . "' and cdr.end <= '" . $enddate . "' limit 30"; $result =mysql_query($qryCDR,$conCDR); if(!$result) { $message = 'Invalid query: ' . mysql_error() . '\n' . 'Whole query: ' . $qr$ die($message); } else { while($cdrdata = mysql_fetch_array($result, MYSQL_ASSOC)) $cdrdataarr[] = $cdrdata; } // Terminate Connection mysql_close($conCDR); // Break into Group $clidarr=array(); for($counter=0;$counter<count($cdrdataarr);$counter++) $clidarr[$counter]=explode(" ", $cdrdataarr[$counter]['clid']); for($counter=0;$counter<count($cdrdataarr);$counter++) { $flag=-1; for($index=0;$index<count($clidarr[$counter]) && $flag<0;$index++) { if(strncmp($clidarr[$counter][$index],"G",1)==0) $flag=$index; } if($flag>=0) { $clidarr[$counter][$flag] = substr_replace($clidarr[$counter][$flag], "",$ $cdrdataarr[$counter]['clid']=$clidarr[$counter][$flag]; $GCodeKey = $clidarr[$counter][$flag]; $found = 0; if(count($GCode)==0) $GCode[0]=$clidarr[$counter][$flag]; else { for($index=0;$index<count($GCode) && $found==0;$index++) { if($GCode[$index]==$clidarr[$counter][$flag]) $found=1; } if($found==0) $GCode[count($GCode)] = $clidarr[$counter][$flag]; } } } // The problem starts here // Connect to AsteriskCDR Table $conAsteriskCDR = mysql_connect("10.20.17.8","user","pwd"); if(!$conAsteriskCDR) { die('Could not connect: ' . mysql_error()); } $asteriskCDR = mysql_select_db("asteriskcdr",$conAsteriskCDR); for($row=0;$row<count($cdrdataarr);$row++) { $uniqueID = $cdrdataarr[$row]['uniqueid']; if(!array_key_exists($uniqueID, $uniqueIDarr)) { $qryAsteriskCDR = "SELECT * from queue_actions where uniqueid = " . $un$ $result=mysql_query($qryAsteriskCDR,$conAsteriskCDR); $uniqueIDarr[$uniqueID] = 0; if(!$result) { $message = 'Invalid query: ' . mysql_error() . '\n' . 'Whole query: '$ die($message); } else { while($asteriskcdrdata = mysql_fetch_array($result)) // Main problem $asteriskcdrdataarr[]=$asteriskcdrdata; } } } // Terminate connection mysql_close($conAsteriskCDR); Quote Link to comment https://forums.phpfreaks.com/topic/62681-cross-server-join-and-arrays-not-populating-properly/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.