Forum Stats

  • 3,727,356 Users
  • 2,245,375 Discussions


Using Column Comments instead of Column Title

I have a form on my website that saves data to the database. The fields on the form are named "colour" "shape" "cost". In the database, these form field titles are converted to shortnames by the script. So in the database, the same column names are "mcq1" "mcq2" "mcq3". Each one of the columns in the database have comments in the schema, which contain the actual column name (colour, shape, cost). The question is that when i query the database to show in a table on my website, the table column names show as the mcq1, mcq2, mcq3 names. There are quite a few form fields and i really dont want to use "AS" to rename every column name separately.

Is there a way of fetching the actual column form element names from the schema comment table instead of the short names for the table headers? I cannot find any reference to this type of query. Thankyou in advance


  • dvohra21
    dvohra21 Member Posts: 14,133 Gold Crown

    A comment is not selectable in SELECT. The comment is displayed by the SHOW CREATE TABLE and SHOW FULL COLUMNS statements.

  • dvohra21
    dvohra21 Member Posts: 14,133 Gold Crown

     "mcq1" "mcq2" "mcq3" aren't much shorter than the actual fields on the form. Why not use fields on the form as column names.

  • User_L3HE5
    User_L3HE5 Member Posts: 2

    Thankyou for taking the time to answer.

    I am just learning the basics of mysql so slowly picking my way through books and website snippets. The form script is something I bought from codecanyon for a project but I need to display results in additional pages. I can do this, but just can't figure this comments part out.

    The column names would be quite long as they would be the questions on the form with a yes no answer. There are around 20 questions on the form, so using Alias / As would be a massive statement.

    Can you give any pointers or any snippets that may help my journey? Your answer is very much appreciated. I will get googling now :)

  • dvohra21
    dvohra21 Member Posts: 14,133 Gold Crown

    Is some MySQL IDE used? Some GUI IDEs support automatic code completion for aliases.

Sign In or Register to comment.