Jump to content

Recommended Posts

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.