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: 
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.
Use `mysql_query()` and execute this query: 

```
 SHOW COLUMNS FROM table 

```

Example:

```
<?php
 $result = mysql_query("SHOW COLUMNS FROM sometable");
 if (!$result) {
  echo 'Could not run query: ' . mysql_error();
  exit;
 }
 if (mysql_num_rows($result) > 0) {
  while ($row = mysql_fetch_assoc($result)) {
    print_r($row);
  }
 }
 ?>

```