Php - echo MySql column names and values
<p>What I need is to have a list name => value to be able to make MySql queries. My proble is, I can access MySql records, but I also need to access to the table column names, what should I change in my code?</p>

<p>Thanks</p>

<pre><code>$query = "SELECT * FROM test_table";
$result = mysql_query($query) or die("Erro!: " . mysql_error());
if (mysql_num_rows($result) &gt; 0) {
    $row = mysql_fetch_array($result);
    if(is_array($row)) {
        foreach ($row as $col =&gt; $val) {
            echo $col." = ".$val."&lt;br&gt;";
        }
    }
}
</code></pre>

<p>ok, so now why can't I join the values to then make my sql queries?</p>

<pre><code>while($row = mysql_fetch_assoc($result)) {
        foreach ($row as $col =&gt; $val) {
            $colunas .= join(",",$col);
            $valores .= join(",",$val);
        }
        echo "colunas = ".$col."&lt;br&gt;";
        echo "valores = ".$val."&lt;br&gt;";
    }
</code></pre>

<p>I just get empty colunas and valores</p>

<p>Thanks, sorry if it seems to easy, but I'm lost</p>
