ID:               48015
 Updated by:       [email protected]
 Reported By:      blackmagic at computer dot org
-Status:           Open
+Status:           Feedback
 Bug Type:         PostgreSQL related
 Operating System: Centos 5.3
 PHP Version:      5.2.9
 New Comment:

Try 'var_dump($company);' and it should be clear..


Previous Comments:
------------------------------------------------------------------------

[2009-04-19 11:20:58] blackmagic at computer dot org

Description:
------------
A Postgresql query returns an array. If the array is imploded each 
value in the original array appears twice in the implosion.

Assume a Postgresql result array contains $array[0], $array[1], 
$array[2]; 
$x=implode ('|', $array) puts
$array[0]|$array[0]|$array[1]|$array[1]|$array[2]|$array[2] into $x.
$x=$array[0]. '|' . $array[1]. '|' . $array[2]; works fine.
Why is there a difference?

Reproduce code:
---------------
<?php
$company;                                                              
                           $details;                                    
                                                      $index;           
                                                                      
require_once('../functions/sql_functions.inc');                        
                           database_connect();                          
                                                     $db_query = "SELECT
* FROM company ORDER BY id ";
database_query(__FILE__, __LINE__);                                    
                       if ($db_rows == 0) echo $DB_EMPTY_FILE;          
                                                                        
                                  
else {
for ($index=0; $index<$db_rows; $index++) {                            
                                            $details =
pg_fetch_array($db_result, $index);                                     
                $company[$index] = implode('|', $details); }   //THE BUG
IS HERE//                                                     $details =
implode('^', $company);                                                 
                 echo "$details"; }                                     
                                                                        
                                      


Expected result:
----------------
I expected to see:
$company[$index] = $details[0]|$details[1]|$details[2].




Actual result:
--------------
Actual result:
$company[$index] = 
$details[0]|$details[0]|$details[1]|$details[1]|$details[2]|$details[
2].

This program was working fine until I changed 
$company[$index] = $details[0]. '|' . $details[1]. '|' . $details[2];
to
$company[$index] = implode('|', $details);





------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=48015&edit=1

Reply via email to