title: php variable as a mysql column name
body: <p>I tried to find solution for this about everywhere, but nothing Google gave seems to work for my specific case.</p>
  
  <p>My table has 4 columns that I want updated that I have named 0, 1, 2, 3, conveniently as I have to loop through it to update.
  Here is one instance of the column structure :</p>
  
  <pre><code> column name 0 ENUM('Y','N') null=no default='N'
  </code></pre>
  
  <p>Now I want to set the value to 'Y' using this loop, but it will not accept the way I am referring to the $i variable within the query. </p>
  
  <p>See below my last attempt. I also tried to cast $i as int, but that did not work either.</p>
  
  <p>I appreciate your guidance on this.</p>
  
  <pre><code>                     /* update versions columns to Y where applicable */
          for ($i=0;$i &lt;= $ctvid-1;$i++){
          $sql = mysql_query (
          "SELECT trim_id
          FROM versiontrim
          WHERE (
          version_id =$arr_vid[$i]
          )");
          $escapedi=mysql_real_escape_string($i);
          while ($row1 = mysql_fetch_assoc( $sql ))
          {
          $r=$row1['trim_id'];
          mysql_query ("UPDATE ttcomp SET '".$escapedi."' ='Y' where         trim_id=$r ");
          }
                      }
  </code></pre>