Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5997109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:12:57+00:00 2026-05-23T00:12:57+00:00

I am a beginner to PHP and MySQL so please bear with me… I

  • 0

I am a beginner to PHP and MySQL so please bear with me…

I am trying to get the field values of a mysql table using a for loop. I know to how to get it by using mysql_fetch_array but the thing is I have to specify each field. I want to do it by just getting the number of fields and use a loop to get the values. I also tried mysql_fetch_field but I can’t find any functions that return the value.

Here is the list of mysql_fetch_field return values:

  • name – column name
  • table – name of the table the column belongs to
  • max_length – maximum length of the column
  • not_null – 1 if the column cannot be NULL
  • primary_key – 1 if the column is a primary key
  • unique_key – 1 if the column is a unique key
  • multiple_key – 1 if the column is a non-unique key
  • numeric – 1 if the column is numeric
  • blob – 1 if the column is a BLOB
  • type – the type of the column
  • unsigned – 1 if the column is unsigned
  • zerofill – 1 if the column is zero-filled

I also tried reading about mysql_result but it seems that you have to specify the field.

mysql_result [field]

The name or offset of the field being retrieved.

It can be the field’s offset, the field’s name, or the field’s table dot field name (tablename.fieldname). If the column name has been aliased (‘select foo as bar from…’), use the alias instead of the column name. If undefined, the first field is retrieved.

Here is my code fragment:

<table> 
 <tr>
  <?php
   for ($i = 0; $i < mysql_num_fields($result); ++$i) echo  "<th>" . mysql_field_name($result, $i) . "</th>"  ;
  ?>
 </tr>
 <?php 
  for ($i = 0; $i < mysql_num_rows($result); ++$i) {  
   echo "<tr>";
   for ($j = 0; $j < mysql_num_fields($result); ++$j) {
    echo "<td>" . // this is where I want to put the function . "</td>";
   }
   echo "</tr>";
  }
 ?>
</table>

Pls help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:12:58+00:00Added an answer on May 23, 2026 at 12:12 am

    I use this function I made which returns all the results from the SQL into an array.

    <?php
    function getResultRows($result)
    {
        $rows = array();
        while ($row = mysql_fetch_array($result)){
            $rows[] = $row;
        }
        return $rows;
    }
    
    $sql = 'SELECT * FROM myTable WHERE 1=1';
    $result = mysql_query($sql);
    $rows = getResultRows($result);
    print_r($rows);
    ?>
    
    array(
        [0]array(
            [0]id => 0
            [1]name => blah
        )
        [1]array(
            [0]id => 5
            [1]name => test
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a complete beginner trying to develop for FCKeditor so please bear with
Im a complete beginner with Apache re-writes. Im trying to get example.com/forum to be
A beginner question, bear with me: I'm just wondering under what circumstances one should
What database should a beginner use in the C language? Can I use MySQL?
As a complete beginner with no programming experience, I am trying to find beautiful
I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the
I'm a PHP/MySQL noob who knows nothing about online security. Could you point me
I'm a beginner and trying to generate as much of my own code as
How do I encrypt a user password in PHP ? Please explain in a
I'm just a beginner, What's wrong with my code, I'm trying to experiment on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.