Problem with functions and arrays...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey Everyone!

So I came across a problem that I don't know how to fix... I have searched and thought and just not having anything click as to where I am messing up...

I have a few functions as follows:
<?PHP

function ddbYear($name, $message, $_POST, $option){

    //Make sure to post form start/stop OUTSIDE of this function...
    //It's not meant to be a one size fits all function!
echo "NAME: " . $name . "<BR>";
echo "MESSAGE: " . $message . "<BR>";

echo "POST: " . $_POST . "<BR>";
echo "OPTION: " . $option . "<BR>";


$sticky = '';
if(isset($_POST['submit'])) {
$sticky = $_POST["{$name}"];
echo "STICKY: " . $sticky;
}
//echo "OPTION: ";
//print_r($option);

    echo <<<HTML
<select name="{$name}">
<option value="0">{$message}</option>

HTML;

foreach ($option as $key => $value){

if($key == $sticky) {
echo '<option value="' . $key .'" selected>' . $value . '</option>';
}else{
echo '<option value="' . $key .'">' . $value . '</option>';
}

}

echo <<<HTML

</select>
HTML;
unset($value);
return;
}

?>

One for Month, Day & Year... All the same exact code... When I get brave I'll combine it into 1 functions :)

Now... What it's trying to do.. It's on a "update" form on my website. Basically pulls the info from the database and displays it in the form again so it can be edited and resubmitted...

As I'm sure you can tell from the function it checks to see if the a value has been selected in the drop down box and if it has then set the drop down box to that value.

I call the function like this:
<?PHP
$startYear = date("Y", $row['startdate']); //Actual DBValue: 1265000400
$optionYear = array("2010" => "2010", "2011" => "2011", "2012" => "2012", "2013" => "2013", "2014" => "2014");

ddbYear("startYear", "Select Year", $startYear, $optionYear);


?>

The output I'm getting is:
THESE ARE THE ACTUAL UNPROCESSED (OTHER THEN SEPARATING) VALUES FROM THE DATABASE
startmonth: 2
startday: 1
startYear: 2010
endmonth: 11
endDay: 30
endYear: 1999

THESE ARE THE VALUES INSIDE THE FUNCTION
NAME: startYear
MESSAGE: Select Year
POST: 2010
OPTION: Array
STICKY: 2

Now... The problem is that $sticky get set to "2" instead of "2010"... But I can't figure out why...

Anyone have any ideas?

And just incase I didn't provide enough info here's a link that shows it happening:

HTTP://jason.pruimphotography.com/dev/cms2/events/update_form.php?id=62

Thanks for looking and for your answers in advance! :)



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux