Selecting info from a MySQL DB...

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
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Selecting info from a MySQL DB...

Post 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?
User avatar
riley
Forum Commoner
Posts: 45
Joined: Thu May 02, 2002 6:31 pm

Post 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)
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

Very cool.

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

Ideas?

Graci!
User avatar
riley
Forum Commoner
Posts: 45
Joined: Thu May 02, 2002 6:31 pm

Post 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;
Post Reply