Page 1 of 1

Is there any way to select a comment on a column in a mysql?

Posted: Tue Aug 11, 2009 9:10 pm
by sobha
Is there any way to select a comment on a column in a mysql query?Can it be done (and used
with php)?Or is there any built-in php functions for doing it?

Regards,
Sobha

Re: Is there any way to select a comment on a column in a mysql?

Posted: Tue Aug 11, 2009 10:04 pm
by requinix
You can treat the results of

Code: Select all

SHOW FULL COLUMNS FOR table
as if it were a regular SELECT query...

Re: Is there any way to select a comment on a column in a mysql?

Posted: Tue Aug 11, 2009 10:15 pm
by sobha
Thanks for your reply.Is there any way to display only the comments in all the column fileds rather than all the column fields in mysql using PHP?Or is there any special functions in php to do that ?
To display column field we use mysql_field_name().Similarly is there any php functions to display comment in column field of mysql

Re: Is there any way to select a comment on a column in a mysql?

Posted: Tue Aug 11, 2009 11:47 pm
by neuroxik
I can't seem to find the exact solution (for teh query part) but here's a way you could display only the columns and their comments:

Code: Select all

 
$sql = mysql_query("SHOW FULL COLUMNS FROM table_name_here",$link);
 
while($r=mysql_fetch_assoc($sql)) { 
    if(!empty($r['Comment'])) {
        echo "Table ".$r['Field']." has the following comment: ".$r['Comment']."<br />";
    }
 
}
 


The array call is case-sensitive, that's why I put an uppercase F to $r['Field'] and C to Comment

Re: Is there any way to select a comment on a column in a mysql?

Posted: Wed Aug 12, 2009 12:09 am
by sobha
Thanks for ur reply.I didnt understand $link.What is it supposed to be?

Re: Is there any way to select a comment on a column in a mysql?

Posted: Wed Aug 12, 2009 12:12 am
by sobha
Did u mean $link = mysql_connect($dbs,$dbu,$dbpw)

Re: Is there any way to select a comment on a column in a mysql?

Posted: Wed Aug 12, 2009 12:15 am
by neuroxik
Yeh, $link referred to the db connection, sorry I didn't specify.

I checked the MySQL manual didn't find any direct query that would specifically retrieve the comment rows, also because to get the COMMENT field/column, you need to supply the FULL keyword. So I guess you couldn't really do otherwise than grab all the data as an array and loop to see the occurences in each table instance.

Did it work out on your side?

Re: Is there any way to select a comment on a column in a mysql?

Posted: Wed Aug 12, 2009 12:21 am
by sobha
Thanks for your effort for going thru the MYSQL manual.No it is not working.
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource.
what should i use instead of mysql_fetch_assoc()?

Re: Is there any way to select a comment on a column in a mysql?

Posted: Wed Aug 12, 2009 12:31 am
by neuroxik
Alright, then it must be a variable that hasn't been changed correctly, cuz mysql_fetch_assoc() should work and usually that kind of error is given when example your database connection is not correctly associated with the mysql_fetch_assoc() function.

Check below:

Code: Select all

[color=#DF1B1B]$sql[/color] = mysql_query("SHOW FULL COLUMNS FROM your_table_name_here ",[b]$link[/b]);
 
while($r=mysql_fetch_assoc([color=#DF1B1B]$sql[/color])) { 
//..
}
 
1 - In the above code, I put the variable $sql in red. Are you sure they correspond in yours? Meaning, if you named your query $some_query_name, have you done the same in mysql_fetch_assoc($some_query_name)

2 - Change the variable $link (from my code) to your database connection variable. So, if you connect using $some_variable like this: $some_variable = mysql_connect($host, $user, $pwd), have you changed $link to your $some_variable ?

If these don't resolve the situation tell me.

UPDATE : And of course, make sure that your_table_name_here (that I called table_name_here in my first post) is replaced by the name of your table.

Re: Is there any way to select a comment on a column in a mysql?

Posted: Wed Aug 12, 2009 12:35 am
by sobha
It worked now for me .Thanks for your reply.

select comment on a column from two tables in a mysql?

Posted: Wed Aug 12, 2009 9:20 pm
by sobha
How to select comment on a column from two tables in a mysql?
I tried this.But it shows error.What is the syntax to be used?
SHOW FULL COLUMNS FROM table1 , table2;

Re: Is there any way to select a comment on a column in a mysql?

Posted: Thu Aug 13, 2009 10:40 am
by neuroxik
It depends on what you want, because you can use INNER JOIN, LEFT JOIN or RIGHT JOIN.

Example:
SHOW FULL COLUMNS FROM table1 INNER JOIN table2

I've never done this with SHOW, only on SELECTs, so I'm not sure but usually a select joining two tables could look like this:

SELECT * FROM table1 INNER JOIN table2 on table1.column_name_here = table2.column_name_here

If I have time, I'll test it with SHOW FULL.

Re: Is there any way to select a comment on a column in a mysql?

Posted: Thu Aug 13, 2009 10:47 am
by aceconcepts

Code: Select all

SELECT * FROM user_col_comments WHERE table_name = 'your_table_name'

Re: Is there any way to select a comment on a column in a mysql?

Posted: Thu Aug 13, 2009 7:23 pm
by sobha
SHOW FULL COLUMNS FROM table1 INNER JOIN table2 shows sql syntax error.