Jump to content

Archived

This topic is now archived and is closed to further replies.

johnska7

Grabbing MySQL column comments

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.

Share this post


Link to post
Share on other sites
assuming comments is a feature describing something about the column itself (like the type, special options, etc.), look in the MySQL manual for the DESCRIBE statement.

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Perfect! I need to figure out how to get it to flow with what I already have, but it's great.

And I figured out why it wasn't showing before...I was selecting the wrong table...TGIF :)

Share this post


Link to post
Share on other sites

×

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.