We help IT Professionals succeed at work.
Get Started

cant print mysql table info(broken)

Johnny asked
Last Modified: 2013-12-12
im trying to print out info from a mysql table both field names and record data.

for some reason it only prints the first 0 records data but stops there any ideas why and how to fix this please?

if i search for a field name it only returns the first one
$search_for="first_name, account_owner";
first name is returned nothing else

account owner is returned nothing else

ID is first field only returns ID

it does print out the field names all 22 of them just no data after first record data

please see attached code

thank you in advance for any help or code you may provide

$id = $_REQUEST['id'];
// any table name and where is will work
$result = mysql_query("SELECT * FROM contacts where ID='".$id."'" );
echo "Displaying Record Number: ".$id."<br>\n";
$numfields=mysql_num_fields($result); // count the number of results
//echo mysql_num_fields($result);
for($i=0; $i<$numfields; $i++) // print out the results and column names 1 at a time
$fieldName = mysql_field_name($result,$i);
$myrow=mysql_fetch_array($result,MYSQL_NUM); // set the results into array row
//$row = mysql_fetch_assoc($result);
echo"$i: ";
echo" - ";
echo "{$myrow[$i]}";
//echo "{$row[$fieldName]}";
} // of of for loop

Open in new window

Watch Question
Lead Developer
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE