php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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";
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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: Fri Jan 17 15:01:24 2020 UTC