title: Get column names and values in for loop PHP
body: <p>I would like to get all column names and values from a specific table.
  The fields in this table aren't fixed, so sometimes there will be added one field by the user and they also can be removed. What I want to do is retrieve all column names and getting the values of it. As far as I am now is retrieving the column names and getting one value out of it. I know why I get this result, but I don'tknow how to fix it.</p>
  
  <pre><code>//I edited this sql, normally the table value and id are variable
  $sql = "SELECT * FROM ".$_POST['moduleName']." WHERE modItemID= ".$_POST['modItemID']; 
  $query = mysql_query($sql); 
  $columns = mysql_num_fields($query); 
  for($i = 1; $i &lt; $columns; $i++) { 
  
  //read field name
    $fieldName = mysql_field_name($query,$i);
    while($row = mysql_fetch_assoc($query,$i)){
      echo $fieldName."=".$row[$fieldName];   
    }
  
  }  
  </code></pre>
  
  <p>result:
  naam=Ketting</p>