I normally use a value of 0 to indicate a search of "All Values".
The first thing you do is create a class at the top of your page as follows:
<?php
class MySelectObject{
var $id;
var $name;
}
?>
Then to use it do the following:
<?php
$db = &JFactory::getDBO();
$query = "SELECT `id`,`name` FROM
#__town";
$db->setQuery($query);
$townlist = $db->loadObjectList();/*Create an instance of MySelectObject*/
$mso = new MySelectObject();/*Set values*/
$mso->id = 0;
$mso->name = 'Any Town';/*Create an array for insertion*/
$tmpArr = array(0 => $mso);/*Merge with array result from query. Add to the front of list*/
$selectList =
array_merge($tmpArr,$townlist);/*Make MySelectObject the default selected*/
echo
JHTML::_('Select.genericlist',$selectList,'town',"","id","name",0);
?>