Rename MYSQL column names for php select element -


hi i'm constructing html select element so:

$result = mysql_query("show columns table") or die(mysql_error());     echo '<select name="column" class="column">';     while ($row = mysql_fetch_array($result))     {         if($row[0] == 'id' || $row[0] == 'tstamp' || $row[0] == 'boiler2oil')               continue;         echo "<option value='".$row[0]."'>".ucwords($row[0])."</option>";     }     echo '</select>'; 

the way i've named columns in table rather ugly, underscores, etc...how can rename them can change select element display (value can stay same) changes bit more readable , visually pleasing. possible? sort of preg_match/preg_replace?

depends want rename them to. want simple remove underscores? there rule can use clean them up?

if not, why not add hash entries map name in table name want print out drop-down list?

# map column name display name $labels = array(     'col1' => 'column 1',     ... );  $result = mysql_query("show columns table") or die(mysql_error()); echo '<select name="column" class="column">'; while ($row = mysql_fetch_array($result)) {     if($row[0] == 'id' || $row[0] == 'tstamp' || $row[0] == 'boiler2oil')           continue;      # use more friendly name if 1 has been defined above in $labels     if(array_key_exists($row[0], $labels))           $label = $labels[$row[0]];     else           $label = $row[0];      echo "<option value='".$row[0]."'>".$label."</option>"; } echo '</select>'; 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -