Re: Stumped with select function





supline wrote:
I have a function that creates a select list:

function make_select_ns($name,$array,$persist){
	$string = "<select name=\"$name\">";
	$string .="<option selected>" . ucfirst($name) . "</option>\n";
	if ($name == $array[0]){array_shift($array);} //removes duplicate when
table name equals 1st item in array
		foreach ($array AS $value) {
			if (($value == $persist)  && is_string($persist)){$selected =
"selected";}
			else {$selected = "";}
			$string .= "<option $selected value='" .
str_pad($value,2,"0",STR_PAD_LEFT) . "'>$value</option>\n";
            }
	$string.="</select>";
	print $string;
}

I have arrays for Months, Days, Years, Hours, and Minutes.

All of the arrays work as expected except for the minutes array which
starts at 0 and goes to 55 in increments of 5.  Whenever this loads
after a post the value 0 is selected.  What am I missing here?  Why
does the zero seem to be causing me problems?

Let me know if you need more information.

Alternative solution (with PEAR):

$f = new HTML_QuickForm('life_is_simple');

// assuming $array contains our selections and $selected is
// an array of selected values
$array = array_unique($array); // to remove duplicates
$my_select =& $f->addElement('select', 'my_name', 'Select me:', $array);
$my_select->setSelected($selected)
$f->addElement('submit',null,'Submit');
// or some othe way of displaying it
$f->display();

// end

//Marcin
.



Relevant Pages

  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)