From: ultrageek1 at hotmail dot com
Operating system: Linux
PHP version: 5.2.11
PHP Bug Type: MySQL related
Bug description: foreach returning duplicated data
Description:
------------
I loop through MYSQL data with a mysql_data_seek() and a while loop. and I
loop through each row returned with a foreach() loop.
function accepts a MYSQL resource as input ($data) along with an optional
array of table headers ($head) which might only have one element.
This is PHP 5.2.10, not .11
I would have to ask my hosting provider to upgrade the PHP version.
no variables pass by reference.
Reproduce code:
---------------
<?php
function build_table($data,$head = null){
echo "<table>";
if ($head){
foreach ($head as $h)
echo "<th>".$h."</th>\n";
}
if (is_resource($data)){
mysql_data_seek($data,0);
while($row = mysql_fetch_array($data)){
echo "<tr>";
foreach($row as $cell){
echo "<td>".($cell)."</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
}
}?>
Expected result:
----------------
head1 (head2 head3)
r1d1 r1d2 r1d3 r1d4
r2d1 r2d2 r2d3 r2d4
r3d1 r3d2 r3d3 r3d4
....
Actual result:
--------------
head1 (head2 head3)
r1d1 r1d1 r1d2 r1d2 r1d3 r1d3 r1d4 r1d4
r2d1 r2d1 r2d2 r2d2 r2d3 r2d3 r2d4 r2d4
r3d1 r3d1 r3d2 r3d2 r3d3 r3d3 r3d4 r3d4
....
--
Edit bug report at http://bugs.php.net/?id=50259&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=50259&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=50259&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=50259&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=50259&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=50259&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=50259&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=50259&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=50259&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=50259&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=50259&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=50259&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=50259&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=50259&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=50259&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=50259&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=50259&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=50259&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=50259&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=50259&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=50259&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=50259&r=mysqlcfg