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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

You can treat the results of

Code: Select all

SHOW FULL COLUMNS FOR table
as if it were a regular SELECT query...
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post 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
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

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

Post 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
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post by sobha »

Thanks for ur reply.I didnt understand $link.What is it supposed to be?
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post by sobha »

Did u mean $link = mysql_connect($dbs,$dbu,$dbpw)
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

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

Post 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?
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post 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()?
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

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

Post 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.
Last edited by neuroxik on Wed Aug 12, 2009 12:38 am, edited 2 times in total.
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post by sobha »

It worked now for me .Thanks for your reply.
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post 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;
User avatar
neuroxik
Forum Commoner
Posts: 25
Joined: Tue Aug 11, 2009 10:32 pm

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

Post 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.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

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

Post by aceconcepts »

Code: Select all

SELECT * FROM user_col_comments WHERE table_name = 'your_table_name'
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

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

Post by sobha »

SHOW FULL COLUMNS FROM table1 INNER JOIN table2 shows sql syntax error.
Post Reply