Jump to content

Grabbing MySQL column comments


johnska7

Recommended Posts

Hi all,

I've been trying to find an answer to this and as of yet I've had no luck. What I'm trying to do is access the comment field for a mysql column (field) so that I can use it to display information. I know it's possible, as phpmyadmin displays the comments, but I can't figure out how they do it.

Any help would be greatly appreciated.
Link to comment
Share on other sites

DESCRIBE doesn't show it... Use SHOW with the 'FULL' keyword...

Change table_name for your table

[code]<?php
$sql = "SHOW FULL COLUMNS FROM table_name";
$result = mysql_query($sql);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
echo $row['Comment'];
?>[/code]

Regards
Huggie
Link to comment
Share on other sites

O.k., Huggie, your idea semi worked...I can see the results when I execute that line in mysql admin, but when I try to execute your code (and other iterations) in a web page, I just get a blank screen. Also, I checked to see how many rows were being returned in the fetch and only 5 were returned...I have well over 3000 rows in the database, and about 13 rows that it shows for "fields" when I execute the SHOW in mysql admin...any idea what might be going on?
Link to comment
Share on other sites

Ooops, I forgot the while loop...

[code]<?php
$sql = "SHOW FULL COLUMNS FROM table_name";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  echo "$row['Field'] - $row['Comment']<br>\n";
}
?>[/code]

I also added the 'field' value so that you get the column name too.

Regards
Huggie
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.