How to create XML tags from the column name of a mysql database?

Asked

Viewed 112 times

3

How to create XML tags with the column name of a table coming from a myslq query?

In the code I did I could only get the values of each cell of the table, but what I wanted was to create the tags automatically according to each column.

My current code

2 answers

2


to list the name of your columns in mysql vc uses the following command

$sql = "desc NomeDaTabela";
$result = @mysql_query($sql);
while($row = @mysql_fetch_array($result)){
    echo $row[0]."<br>";
}

2

You can use the information schema to get the column names of your table.

An example you can apply is that:

SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 
   WHERE TABLE_SCHEMA = 'testes' AND TABLE_NAME = 'testes';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.