You're mixing apples and oranges. PHP has the metadata available to it in the form of a column name/value pairs. You scan the results of a query in column order and get the name of the column (from the recordset, not from the data) that has the data you want, right?
A native SQL query, as Paul said, is NOT aware of the column names except as you declare them for use. However, you _can_ write a query that will return a value based on a series of choices. It's much like moving your PHP column scanning loop into your SQL statement. In this case you are nesting a set of IF statements: set @targetValue = 'pid to find'; SELECT user_ID, IF([EMAIL PROTECTED], 'pid0', if(pid1 = @targetValue, 'pid1', if (.... repeat for remaining columns ...))) FROM tablename WHERE ... I didn't type the full statement but I think you can see the pattern. This was just my first idea. I am sure there are others on the list that have done something like this before and can offer their solutions, too. Shawn Green Database Administrator Unimin Corporation - Spruce Pine "Jeremy McEntire" <[EMAIL PROTECTED]> wrote on 09/07/2004 01:38:18 PM: > Clarification. > > I'm using modular arithmetic on a table of recently viewed items. My fields > are: > > user_id, pid0, pid1, pid2, pid3, pid4, inc > > user_id is the user's unique identification. > pid* is the product's unique identification. > inc is a number, modulo 5, corresponding to > the last pid column updated for this user. > > So, when the user visits a page, I want to verify that they > don't currently have this product in their "recently viewed" > list. > > To do so, I'd like to know if the product id is in any of pid0, pid1, pid2, > pid3, or pid4. To accomplish this, I could use a simple OR statement. But, > the information I really want is in which column that product id appears. > Using PHP, I can simply grab the key from the array returned by the query. > I was hoping MySQL offered this functionality; evidently, it does not. > > Sincerely, > Jeremy >