php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2854 mysql_fetch_field won't return object after fetch_row
Submitted: 1999-11-28 21:07 UTC Modified: 1999-11-28 23:01 UTC
From: john-marc at usa dot net Assigned:
Status: Closed Package: MySQL related
PHP Version: 4.0 Beta 2 OS: unix
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: john-marc at usa dot net
New email:
PHP Version: OS:

 

 [1999-11-28 21:07 UTC] john-marc at usa dot net
<?
echo "<HTML><BODY>";
  $db = mysql_connect("localhost", "root");
  $active_db = mysql_select_db("bus");
  $q_sel = "select * from WHO_SHOP ";
  $BusInfo = mysql_query($q_sel ,$db);
  echo "<table border=1>";
  while ($row = mysql_fetch_row($BusInfo)) {
   $fnum=0;
   while ($fn = mysql_fetch_field($BusInfo)) {
     $fieldname = $fn->name;
     $fval= $row[$fnum];
     echo "<TR><TD>$fieldname</TD><TD>$fval</TD></TR>";
     $fnum += 1;
   }
}
echo "</table></HTML></BODY>";
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-28 23:01 UTC] rasmus at cvs dot php dot net
Your code doesn't make a lot of sense.  It isn't like the field names are going to change from one row to the next, so there is no point putting the mysql_fetch_field() inside the row loop.
And if all you want is the name, see the mysql_fetch_array() function.  Call it with a second arg of MYSQL_ASSOC
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 10:01:33 2025 UTC