Jump to content

Combining a collection of variables into one variable.


Toolmaster

Recommended Posts

Hi guys back again with more problems. :-[

I would like to store a collection of variables into one whole variable.

 

This code below shows drop down boxes, which contain the days, months and years.

I would like to store this information into one variable, how would I do this?

 

For example if the user selects 02, March, 2007 then I would like this information to be stored into the database. How can I store each value in the seperate drop down lists into one whole variable?

 

Would appreciate the help, thanks. :)

 

<?php

/* create form containing date selection list */

echo "<form action=’processform.php’ method=’POST’>\n";

 

/* build selection list for the day */

$todayDay= date("d",$today); //get the day from $today

echo "<p>Please select a date: \n";

echo "<select name=’dateDay’>\n";

for ($n=1;$n<=31;$n++)

{

echo " <option value=$n";

if ($todayDay == $n )

{

echo " selected";

}

echo "> $n\n";

}

echo "</select>\n";

 

/* build selection list for the month */

$todayMO = date("m",$today); //get the month from $today

echo "<select name=’dateMO’>\n";

for ($n=$todayMO+0;$n<=$todayMO+1;$n++)

{

echo "<option value=$n\n";

if ($todayMO == $n)

{echo " selected";

}

echo "> $monthName[$n]\n";

}

echo "</select>";

 

/* build selection list for the year */

$startYr = date("Y", $today); //get the year from $today

echo "<select name=’dateYr’>\n";

for ($n=$startYr;$n<=$startYr+1;$n++)

{

echo " <option value=$n";

if ($startYr == $n )

{

echo " selected";

}

echo "> $n\n";

}

echo "</select>\n";

echo $appointment_date = 'dateDay', 'dateMO',  'dateYr'; (i've attempted it this way, but it doesn't work. :( )

echo "</form>\n";

?>

In the OP's original example ... why not simply use the form POSTed data to generate the date in the (useful) form yyyy-mm-dd since that's ideal for simple comparisons.

 

In your sample code, the selected date is never going to show since the values selected are not available until the submit - which your form doesn't even contain!! - is pressed.  Then you can abstract the individual values of DateDatm dateMO, and dateYr from the POSTed array and use mktime() to generate the date.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.