Hey everyone,
I have a problem and hope someone can guide me in the right direction.
I have a site that stores dates in a mysql database. I am currently making an update page so that people can update their entry.
The update page when displayed needs to populate itself with entries from mysql. My update page updates with no problem all the fields except for the date drop down boxes. I am having a problem with the variables.
The data that is pre entered into the update page comes from a mysql array. I assign variables to each part of the array like below. I have 4 date drop down boxes and they follow the pattern below
$date1stpieces = explode("-",$date1st);
$day1 = $date1stpieces[0];
$mon1 = $date1stpieces[1];
$yea1 = $date1stpieces[2];
//split up $date2ndnoa into an array
$date2ndpieces = explode("-",$date2nd);
$day2 = $date2ndpieces[0];
$mon2 = $date2ndpieces[1];
$yea2 = $date2ndpieces[2];
I call the function like so
for ($num = 1; $num <= 4; $num++)
{
$display_block .= makeaform($desc,$num);
}
THe theory is that the form variables are mon1,day1,yea1/mon2,day2,yea2....
I try to create the variable as shown below '$mon.$num'. THe only thing I can get it to do is populate the month field with January in mon1 February in mon2 etc. So it is obviousy recognizing only the $num variable. I am trying to merge the variables so that $mon.$num will make $mon1, $mon2, $mon3, $mon4. Then display the data from that variable that is created from mysql earlier in the page. I hope I have explained this clearly and appreciate any help provided.
function makeaform($desc,$num)
{
$montharray=array(1 => 'January','February','March','April','May','June','July','August','September','October','November','December');
$yeararray = array('1' => "2004","2005","2006"); //set up array
$combined = "'month'.$num";
echo $combined;
$bob =
"<tr><td>$desc[$num]</td>
<td>
<select name=\"$mon.$num\">
<option value=\"\"></option>";
foreach ($montharray as $ind => $value)
{
if ($mon.$num == $ind)
{
$selected = '" selected="selected"';
}
else
{
$selected= '';
}
$bob .=
"
<option value=\"$ind\"$selected>$value</option>
";
}
$bob.=
"
</select>
<select name=\"day$num\">
<option value=\"\"></option>
";
for ($i = 1; $i <= 31; $i++)
{
$bob .=
"
<option value=\"$i\"$selected>$i</option>
";
}
$bob .=
"
</select>
<select name=\"year$num\">
<option value=\"\"></option>
";
foreach ($yeararray as $ind => $value)
{
if ($_POST["year1"] == $value)
{
$selected = '" selected="selected"';
}
else
{
$selected= '';
}
$bob .=
"
<option value=\"$value\"$selected>$value</option>
";
}
$bob .=
"
</select>
";
return $bob;
}