Question: I want to execute a SELECT query but I don't how many columns to select.

Like:

```
select name, family from persons;

```

How can I know which columns to select?

"I am currently designing a site for the execute query by users.
So when the user executes this query, I won't know which columns selected.
But when I want to show the results and draw a table for the user I should know which columns selected."

Answer: 
For unknown query fields, you can just use this code. 

It gives you every row fields name=>data. You can even change the key to `''` to get ordered array columns by num following the columns' order in the database. 

```
$data = array();
while($row = mysql_fetch_assoc($query))
{
    foreach($row as $key => $value) {
        $data[$row['id']][$key] = $value;
    }
}
print_r($data);

```
If I understand what you are asking, you probably want to use MySQLIi and the the fetch\_fields method on the result set:

<http://us3.php.net/manual/en/mysqli-result.fetch-fields.php>

See the examples on that page.