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 1090109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:19:23+00:00 2026-05-16T23:19:23+00:00

There is a problem of automatically retrieving field names from a MySQL table. If

  • 0

There is a problem of automatically retrieving field names from a MySQL table. If possible could the name be placed in this format along with the dynamically created text box? :

The codes that I have created so far are located below:

<?php

include "db_connect.php";

$name = mysql_query("SELECT * from users");

$property = mysql_fetch_field($name);

$i = 0;

$result = mysql_query("SHOW COLUMNS FROM users");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
    while($i<mysql_num_fields($result))
    {
      $meta=mysql_fetch_field($name,$i);
      $new = $meta->name;
      echo "$new: <input type=\"text\" name=\"{$row['Field']}\" size=\"40\"   
      maxlength=\"256\" /><br>";
      $i++;
    }
}
}
?>

The Dynamically created text box (according to the number of columns from the table) are working fine but the field names cannot be generated! Can someone please give advice or help on this? Thanks!

  • 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-16T23:19:23+00:00Added an answer on May 16, 2026 at 11:19 pm

    Code below will get table columns and generate the list of inputs. In you code you have a lot of things that are useless. You do not need to select * from users…

    Here is the code

    <?php
    include "db_connect.php";
    
    //  This is not needed! Useless query that loads all the info from db
    //$name = mysql_query("SELECT * from users");
    //$i = 0;
    
    //  Here you are getting columns information
    $result = mysql_query("SHOW COLUMNS FROM users");
    
    if (!$result) {
        echo 'Could not run query: ' . mysql_error();
        exit;
    }
    
    //  Scan through all the columns
    while ($field = mysql_fetch_object($result)) {
    
        //  structure of $field looks like this
        /*
          object(stdClass)[1]
          public 'Field' => string 'id' (length=2)
          public 'Type' => string 'int(11)' (length=7)
          public 'Null' => string 'NO' (length=2)
          public 'Key' => string 'PRI' (length=3)
          public 'Default' => null
          public 'Extra' => string 'auto_increment' (length=14)
         */
    
        //
        echo "$field->Field: <input type=\"text\" name=\"$field->Field\" size=\"40\" maxlength=\"256\" /><br>";
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone else out there had this problem and found a possible solution. Im
Is there a problem with this type of implementation to wait for a batch
Consider this problem: There's a square grid defined, each tile being either passable (1)
what's the problem there, I have uploaded this video to server, but now its
Possible Duplicates: Is there a problem that has only a recursive solution? Can every
I have a following problem: There is a 3rd party extension which automatically adds
Problem There are data gaps that need to be filled. Would like to avoid
Problem: There are a lot of different databases, which is populated by many different
Is there any problem with my code ? std::vector<int[2]> weights; int weight[2] = {1,2};
is there any problem to install different oracle 11g versions. I mean if I

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.