the optlist creation is now.....
Code: Select all
<?php
function array_to_options($array, $method, $feild_name){
echo "in ato, feild name $feild_name; method $method; array $array <br /> {$$method}[$feild_name] <br />"; # debug
$optlist=array(); # make an empty array
foreach($array as $key=>$value){
if($method[$feild_name]==$key){ # if this is the first time it wont match, so we don't need to care if it's set
$optlist[]="<option value="$key" selected>$value</option>";
}else{
$optlist[]="<option value="$key">$value</option>";
}
}
return $optlist;
}
?>
and that gets....
in ato, feild name month; method $_POST; array Array
[month]
Array
in response. obviously i know now why the array is empty. gonna try without your extra $ and report back
reporting back...
Code: Select all
<?php
function array_to_options($array, $method, $feild_name){
echo "in ato, feild name $feild_name; method $method; array $array <br /> {$$method}[$feild_name] <br />"; # debug
$optlist=array(); # make an empty array
foreach($array as $key=>$value){
if($method[$feild_name]==$key){ # if this is the first time it wont match, so we don't need to care if it's set
$optlist[]="<option value="$key" selected>$value</option>";
}else{
$optlist[]="<option value="$key">$value</option>";
}
}
return $optlist;
}
?>
gets
in ato, feild name month; method $_POST; array Array
$_POST[month]
Array
slightly better... now how do i get it to put together the array based on it??? obviously i am getting close.
btw: i named the function and feilds like i did because i can see others wanting to use this and since there's nothing and i found this trick useful n making a page with options and memory, i figure i might as well send it into php.net since i need to make it anyway so i can call it from two pages... one the sign up and one searching since i use the same arrays and this is how i'm turning them into options
edit:
i realized that i am trying to get a string. so i made some changes, but....
the default selected thing doesn't seem to work
new code:
Code: Select all
function array_to_options($array, $method, $feild_name){
echo "in ato, feild name $feild_name; method $method; array $array <br /> {$method}[$feild_name] <br />"; # debug
$optlist=''; # make an empty string
foreach($array as $key=>$value){
if($method[$feild_name]==$key){ # if this is the first time it wont match, so we don't need to care if it's set
$optlist=$optlist."<option value="$key" selected>$value</option>";
}else{
$optlist=$optlist."<option value="$key">$value</option>";
}
}
return $optlist;
}
and
Code: Select all
<?php
include("/home/joshua/includes/fyd.incs.php"); # includes file
$month=$_POST['month'];
if(!isset($month)){
echo <<<END
<html><head></head><body>
<form action="$_SERVER[PHP_SELF]" method="post">
<input type="text" name="month">
<input type="submit" value="check">
</form>
</body></html>
END;
}else{
$array=array('00'=>'Month', '01'=>'January', '02'=>'February', '03'=>'March', '04'=>'April', '05'=>'May', '06'=>'June', '07'=>'July', '08'=>'August', '09'=>'September', '10'=>'October', '11'=>'November', '12'=>'December');
$method='$_POST';
$feild_name="'month'";
$list=array_to_options($array, $method, $feild_name);
echo '<select name="test" size="1">'.$list.'</select>';
}
?>
generates
in ato, feild name 'month'; method $_POST; array Array <br /> $_POST['month'] <br /><select name="test" size="1"><option value="00">Month</option><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select>