Toolmaster Posted March 30, 2007 Share Posted March 30, 2007 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"; ?> Link to comment https://forums.phpfreaks.com/topic/44869-combining-a-collection-of-variables-into-one-variable/ Share on other sites More sharing options...
dsaba Posted March 30, 2007 Share Posted March 30, 2007 .= this syntax adds things to an existing variable for example: $variable = "Hello"; $variable .= " World"; echo $variable; you should get this: Hello World Link to comment https://forums.phpfreaks.com/topic/44869-combining-a-collection-of-variables-into-one-variable/#findComment-217877 Share on other sites More sharing options...
fert Posted March 30, 2007 Share Posted March 30, 2007 $appoitment_date=array("dateDay"=>$_POST['dateDay'],"dateMo"=>$_POST['dateMo'],"dateYr"=>$_POST['dateYr']); I suggest you read about Arrays Link to comment https://forums.phpfreaks.com/topic/44869-combining-a-collection-of-variables-into-one-variable/#findComment-217878 Share on other sites More sharing options...
AndyB Posted March 30, 2007 Share Posted March 30, 2007 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. Link to comment https://forums.phpfreaks.com/topic/44869-combining-a-collection-of-variables-into-one-variable/#findComment-217886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.