Solved

MySQL SELECT COMMENT data in Statement

Posted on 2009-05-11
1
1,128 Views
Last Modified: 2012-05-06
I am dumping some MySQL data and I have used the COMMENT box in phpMyAdmin to give it a nice name. eg. `contact_forname` => 'Contact Forname' and `contact_address_1` => 'Address 1'.

How can I include this data when doing a select??

I am typically doing SELECT * FROM members and the the PHP below.
echo '<table>';
echo '<thead>';
    echo '<tr>';
    foreach($row as $key => $value){
        echo '<th>' . $key . '</th>';  // I WANT THIS TO BE THE CONTENTS OF THE COMMENT BOX!!!
    }
    echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach($result as $row) {
    echo '<tr>';
    foreach($row as $value){
        echo '<td>' .$value . '</td>';
    }
    echo '</tr>';
}
echo '</tbody>';
echo '</table>';

Open in new window

0
Comment
Question by:stmayes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 24354750
You can't select this directly from the table. The comment is meta data, it is not part of the table. There are however two ways you can use to find it:

You can read it from the information_schema database:

select COLUMN_NAME,COLUMN_COMMENT from information_schema.COLUMNS
where TABLE_SCHEMA='YourDatabase' and TABLE_NAME='members';

Alternatively you can do:

SHOW CREATE TABLE members;

Then you must parse the output you get, and fetch the comments.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question