Question: I am trying to compare the field names in the table against the $\_GET field names and if it exists in the table create a Query string, and i am trouble loading the mysql\_field\_name into an array if i do them individually like `$t1 = mysql_field_name($result,1);` it works but loading them all like `$vars = mysql_field_name($result);` dose not seem to work. 

This dose not work

```
$query = array();
$result = mysql_query("SELECT * FROM search_prof");
$vars = mysql_field_name($result);

foreach ($vars as $v)
{
    if (isset($_GET[$v]))
    {
        $query[] = $v.' = "'.addslashes($_GET[$v]).'"';
    }
}
$query = implode(' AND ', $query); 

```

This works

```
$t1 = mysql_field_name($result,1);
$t2 = mysql_field_name($result,2);
$t3 = mysql_field_name($result,3);
$t4 = mysql_field_name($result,4);
$t5 = mysql_field_name($result,5);

    $query = array();
    $result = mysql_query("SELECT * FROM search_prof");
    $vars = array('$t1', '$t2', '$t3', '$t4', '$t5'); 

    foreach ($vars as $v)
    {
        if (isset($_GET[$v]))
        {
            $query[] = $v.' = "'.addslashes($_GET[$v]).'"';
        }
    }
    $query = implode(' AND ', $query); 

```

Answer: 
You should have a look at the php documentation: <http://php.net/manual/de/function.mysql-field-name.php>

The second parameter in this function is NOT optional, so you have to take your second approach.

If you want make it dynamic anyway, you can use the mysql\_num\_field function, which gives you the number of columns. Afterwards you can build a loop, which iterates this much times, calling everytime the mysql\_field\_name function.
You could use something like this to get the fields.

```
$query = array();
$result = mysql_query("SELECT * FROM search_prof");
$numFields = mysql_num_fields($result);
$vars = array();
for ( $i = 0; $i < $numFields; $i++ )
    $vars[] = mysql_field_name($result, $i);

foreach ($vars as $v)
{
    if (isset($_GET[$v]))
    {
        $query[] = $v.' = "'.addslashes($_GET[$v]).'"';
    }
}
$query = implode(' AND ', $query); 

```