The code below extracts the column headings from a database table, starting with the 18th column, and outputs them in a select statement. The problem is that in the last value for the select statement the code below outputs a BLANK output. I realize that the mysql_field_name() functions, they way I've got them written below, are a bit "hacked up". I couldn't get them to work any other way.
Does anyone see why the last value in the <option value=""></option> is blank?
//This code snippet outputs all table column headings starting at column #18.
require_once "./conf/config.inc.php";
$TableName = "State"."$State";
$Result = mysql_query("SELECT * FROM $TableName", $db_connection);
for($i=17; $i<=mysql_num_fields($Result); $i++){
echo "<option value=\"";
echo mysql_field_name($Result, $i);
echo "\">";
echo mysql_field_name($Result, $i);
echo "</option>\n";
}
//This is the output from the code snippet above.
<option value="Albany">Albany</option>
<option value="Allegany">Allegany</option>
//etc.
//etc...
//etc....
<option value="Yates">Yates</option>
<option value=""></option>//****THE LAST ONE HERE IS BLANK!!!
Thanks.
Volitics