create new columns from a variable (PHP & MySQL)

Discussion in 'PHP' started by nesurfer87, Jun 30, 2007.

  1. #1
    Hi,

    I am trying to create a new column in a table where the column name will be equal to the value of a variable.
    
    $trendDate = date("F_j_Y");
    
    $newCol = 'ALTER TABLE trendData ADD $trendDate INT(5)';
    
    mysql_query($newCol); 
    PHP:
    However what's happening is that the new column is just being named $trendDate (not the actual value). Is it possible for me to do what I am trying to do? Thanks in advance!
     
    nesurfer87, Jun 30, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Place the query string between double quotes. Variables won't be parsed between single quotes.
     
    nico_swd, Jun 30, 2007 IP