Droplists for numeric data
Posted: Wed Dec 28, 2005 9:47 am
I've got a form with PHP code that builds a droplist from unique elements in the columns of a table. These droplists are then used to filter the data. This is working out pretty well, but one of my columns is numeric data, and the droplists are being built in such a way that the elements are quoted and thus treated as strings. This of course means I have a nice looking droplist but can't use it to filter the data.
This is obviously not a new problem, but I'm pretty new to all of this and I can't figure out how to make the droplists for numeric data form with intetegers rather than strings.
Can anyone help me?
This is obviously not a new problem, but I'm pretty new to all of this and I can't figure out how to make the droplists for numeric data form with intetegers rather than strings.
Can anyone help me?
Code: Select all
<FORM ENCTYPE="application/x-www-form-urlencoded" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Build and populate the droplists by using an array of column names.
- Distinct values from each column in the EventCombMT table will be used to create a droplist.
- To add or remove a droplist, edit the $columns variable.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
//~~~~~ loop through the array creating a droplist of ~~~~~//
//~~~~~ distinct values for each column in the array ~~~~~//
foreach( $columns as $temp) {
//set up the query
$query = "SELECT DISTINCT $temp FROM EventCombMT ORDER BY $temp;";
$result = odbc_exec($connectionstring, $query);
//now build the droplists for each element in the array in the lines below
?>
<select NAME="<?=$temp?>">
<option VALUE="">All <?=$temp?>s</option>
<?php
// create a droplist element for each item in the array
while(odbc_fetch_into($result, $row)) {
// if this droplist element ($row[0]) was passed as a parameter($_GET[$temp]), set the option as selected and give it a distinctive appearance.
if (strtoupper($_GET[$temp]) == strtoupper($row[0])) {
print " <option value='".$row[0]."' selected='selected' style='background-color: white;font-weight:bold;color:red;'>".ucwords($row[0])."</option>\n";
} else {
print " <option value='".$row[0]."'>".ucwords($row[0])."</option>\n";
}
}
?>
</select>
<?
}
?>
<INPUT type="submit" value="Apply Filter">
</form>