Page 1 of 1

Selecting info from a MySQL DB...

Posted: Fri Feb 14, 2003 10:26 pm
by Jim
I'm wondering if there's any way to put the name of a field into a variable.

I have several fields that have a value of 0, 1 or 2. I want to be able to pull and print the name of each field that has a specified value (either 0, 1 or 2 depending on what I need.)

Any ideas?

Posted: Sat Feb 15, 2003 6:47 am
by riley
http://www.php.net/manual/en/function.m ... d-name.php

$colname = mysql_field_name($result, $i);

$i is the offset of the returned fields (starts from zero)

Posted: Sat Feb 15, 2003 8:47 am
by Jim
Very cool.

The question now is how to return fieldnames that have values that are not "0".

Ideas?

Graci!

Posted: Sat Feb 15, 2003 6:37 pm
by riley
Well I cant think of a way of limiting cols based on the name of the column only the data within the column. So maybe you could switch the results based on the mysql_field_name result.

Code: Select all

if ( mysql_field_name($result, $i) <> '0' )&#123;

        print "your code here";

&#125;