php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26136 mysql_fetch_row mysql_result interaction
Submitted: 2003-11-05 06:37 UTC Modified: 2003-11-05 11:15 UTC
From: dario_primorac at net dot hr Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.2 OS: Linux
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dario_primorac at net dot hr
New email:
PHP Version: OS:

 

 [2003-11-05 06:37 UTC] dario_primorac at net dot hr
Description:
------------
Table employees has 3 colons (name,surname,position).
The table is filled with 3 values.
When the code is executed it forces a endless while loot,
and the browser must be terminated, and my opinion is that
this code sholuld not do that. My opinion is: the mysql_result and mysql_fetch_row functions are using the same pointer as the handle (return value). It is my opinion that the while loop will go around (n,n+1) value where n is number of row fetched by mysql_result function.

Reproduce code:
---------------
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
echo "<table border=1>\n";
echo "<tr><td>Name</td><td>Position</tr>\n";
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</td></tr>\n", 
mysql_result($result,1,"name") , $myrow[1], $myrow[2]);
}
echo "</table>\n";
?>


Expected result:
----------------
Lets say that the table employee was filled with this data:
name        surname         position
----        -------         --------
Dario       Primorac        1
Mario       Butijer         2
Vido        Vlahinic        3

The result should be:
Name                Position
Mario Primorac      1
Mario Butijer       2
Mario Vlahinic      3

Actual result:
--------------
When the code is executed it forces a endless while loot,
and the browser must be terminated.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-05 11:15 UTC] iliaa@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

Your code is wrong. You should not mix mysql_fetch_row & mysql_result.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 07:01:33 2025 UTC