mysql update dynamic column name
===

I'm trying to UPDATE a table where the column name is a variable so it can be specified through iteration of an array that holds column names.  For example:

    UPDATE my_table
        SET $column_name=$foo
        WHERE something=$bar

The SET syntax is the problem.  I've tried building a query up by concatenation but the nested quote marks are messing me up. The hard wired column specification works.

Here is the actual query i'm trying to build in a version that does not generate a PHP error but fails somewhere.  The idea is to SET column $v to the letter N (simplified detail) in table baccess.

    mysql_query("UPDATE baccess SET " . $v . "=N
    WHERE studentid=$_SESSION[student_id]") 
    or die(mysql_error()); 

 

Thanks