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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 12:01:32 2024 UTC