|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21836 foreach runs 2 times thru array
Submitted: 2003-01-23 03:53 UTC Modified: 2003-01-23 04:28 UTC
From: double-dd at gmx dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.0 OS: Windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: double-dd at gmx dot net
New email:
PHP Version: OS:


 [2003-01-23 03:53 UTC] double-dd at gmx dot net
I have a result from dbx_query that should be written in a table. The outer foreach() runs thru the rows (correctly), the inner foreach() thru the columns of every row. (Just like the example for foreach() in the docu.)
My output are 4 cols(!), the 1st, the 2nd, and again the 1st and the 2nd. But I recieved only 2 columns from the database. When I use a for() instead of foreach() (as commended out), it performs correctly.

$result = dbx_query($dbhandle, "SELECT emp_fname, emp_lname FROM employee;");

foreach($result->data as $row)
  echo "<tr>\n";

  foreach($row as $field) {
    echo "<td>" . $field . "</td>\n"; }

  //for($i = 0; $i < $result->cols; $i++) {
  //  echo "<td>" . $row[$i] . "</td>\n"; }

  echo "</tr>\n";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-23 04:28 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Since the returned array contains the columns both indexed (by columnnumber) and associated (by fieldname) the columns seem to be printed twice.
You can prevent this by using DBX_RESULT_INDEX as the third parameter to dbx_query (provided you don\'t need the fieldnames).

Cheerio, Marc.

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Feb 20 12:01:24 2020 UTC