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
https://forums.phpfreaks.com/topic/23851-grabbing-mysql-column-comments/
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
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?
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

Archived

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

×
×
  • 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.