Droplists for numeric data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scaiferw
Forum Newbie
Posts: 1
Joined: Wed Dec 28, 2005 6:41 am

Droplists for numeric data

Post by scaiferw »

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?

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>
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

When you recieve the input, cast it into a string using (int). I can't really tell you anymore: you have to give us the code that recieves the request. But that's the general jist.
Post Reply