getAssoc

From: Date: Mon, 24 Apr 2000 07:19:12 +0000
Subject: getAssoc
Groups: php.pear 
Request: Send a blank email to php-pear+get-75@lists.php.net to get a copy of this message
I was just going through DB/common.php, and when looking at getAssoc I realized there was a problem... getAssoc returns an associative array where the first column of the row is the index and all of the other columns for that row are an array which is the corresponding value for the first column, something like: array( 'firstcolumn' => array('secondcolumn' ...) ) While this may work if the table you are performing a query on as a unique key as the first column, it won't work were a unique key is not the first column. If the firstcolumn on two rows have duplicate values, then data gets lost... Below are the diffs which will change the structure of the array to the following: array( array('firstcolumn', 'secondcolumn') ) And now the diffs: Index: php4/pear/DB/common.php =================================================================== RCS file: /repository/php4/pear/DB/common.php,v retrieving revision 1.10 diff -r1.10 common.php 338a333 > $x = 0; 344,347c339,340 < // we copy the row of data into a new array < // to get indices running from 0 again < for ($i = 1; $i < $cols; $i++) { < $results[$row[0]][$i-1] = $row[$i]; --- > for ($i = 0; $i < $cols; $i++) { > $results[$x][$i] = $row[$i]; 348a342 > $x++; 353c347,348 < $results[$row[0]] = $row[1]; --- > $results[$x] = array($row[0], $row[1]); > $x++; Comments Welcome, Sterling Hughes sterling@designmultimedia.com

« previous php.pear (#75) next »