Jump to content


Photo

Grabbing MySQL column comments


  • Please log in to reply
6 replies to this topic

#1 johnska7

johnska7
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 13 October 2006 - 02:18 PM

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.

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 October 2006 - 02:28 PM

Are comments a feature of MySQL or phpMyAdmin though?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 13 October 2006 - 02:31 PM

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.

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 October 2006 - 02:36 PM

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

Change table_name for your table

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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 johnska7

johnska7
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 13 October 2006 - 05:58 PM

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?

#6 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 October 2006 - 06:52 PM

Ooops, I forgot the while loop...

<?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";
}
?>

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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#7 johnska7

johnska7
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 13 October 2006 - 07:41 PM

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 :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users