Re: combining 2 arrays

From: Date: Tue, 16 Oct 2007 19:03:05 +0000
Subject: Re: combining 2 arrays
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-263247@lists.php.net to get a copy of this message
nope, merge is not doing what I want and also using FEDERATED <http://localhost/phpmyadmin/server_engines.php?engine=FEDERATED&token=d18a0e0de85e891b3558f84f6585994f> engine in mysql I think is not the simplest way to go or even not appropriate. Anyhow, I did it an ugly way ( tablearray follows DB queries with the same fields; one row of a query is e.g. count=5, server_name="Asterisk" ) Variable dbs is an array with MySQL URIs. Lada function get_data($dbs, $tablearray, $query) { $id = 0; $result = array(); $records = 0; $db_select = 0; for ($c = 0; $c < $len; $c++) {
       $db =& DB::Connect( $dbs[$db_select] );
       if (PEAR::isError($db)) { echo "Can't connect to DB".$db_select."<br>"; }
       else {
           $res = $db->query($query, array() );
           while( $res->fetchInto( $row ) ) {
               $cols = count($row);
               if ($db_select > 0) {
                   for ($i=0; $i < $records; $i++) {
                       if (in_array($row[1],$result[$i])) {
                           $result[$i][$tablearray[0]] = $row[0] + $result[$i][$tablearray[0]];
                           break;
                       }
                       else {
                           if (!@$entered) {
                               @$entered = True;
                               for ($b=0; $b<$cols; $b++) {
                                   $result[$id][$tablearray[$b]] = $row[$b];
                               }
                           $id++;
                           }
                       }
                   }
                   @$entered = False;
               }
               else {
                   for ($i=0; $i<$cols; $i++) {
                       $result[$id][$tablearray[$i]] = $row[$i];
                   }                          $id++;
               }
           }
       }
       $db_select++;
       $records = count($result);
return $result; } Philip Thompson wrote:
On 10/16/07, Greg Donald <greg@cyberfusionconsulting.com> wrote:
On Tue, 16 Oct 2007, Paul Scott wrote:
    
You could try something like:
$result[] = $arrayDB1; $result[] .= $arrayDB2;
      
That .= doesn't do what you think it does when used with arrays.
Take this same concept (of creating a new array) and see if you can use array_merge. I know you mentioned earlier that it wasn't what you were looking for... however, maybe the combination will work??? Good luck, ~Philip


« previous php.general (#263247) next »