Hey,
Ok just wanted to find out why the following isn't possible.
I have a form that queries the database, some of this data is in DATE format. So, I have three dropdown menus - one for day, month and year.
Problem is I have a start and end date, so instead of replicating the same file twice I am using the same file, but inside a function as follows:
// $type - either day, month or year
// $date - either start or end
function insertdate($type, $date) {
// include files
if ($type == "day") {
return include("_includes/date_day.inc.php");
} else if ($type == "month") {
return include("_includes/date_month.inc.php");
} else if ($type == "year") {
return include("_includes/date_year.inc.php");
}
}
Make sense? So inside my query, where I ouput all of my data into my form fields I have the following:
<p><label for="date_start_day">* Date of Event(Start): <br />
<select name="date_start_day">
<? insertdate("day","start"); ?>
</select>
<select name="date_start_month">
<? insertdate("month","start"); ?>
</select>
<select name="date_start_year">
<? insertdate("year","start"); ?>
</select>
</label></p>
Now lets take the year include file for instance, it looks like this:
<option value="2003"<?php if (!(strcmp("2003", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2003</option>
<option value="2004"<?php if (!(strcmp("2004", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2004</option>
<option value="2005"<?php if (!(strcmp("2005", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2005</option>
<option value="2006"<?php if (!(strcmp("2006", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2006</option>
<option value="2007"<?php if (!(strcmp("2007", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2007</option>
<option value="2008"<?php if (!(strcmp("2008", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2008</option>
<option value="2009"<?php if (!(strcmp("2009", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2009</option>
<option value="2010"<?php if (!(strcmp("2010", $row['date_'.$date.'_year'] ))) {echo " SELECTED";} ?>>2010</option>
It doesn't seem to be able to recognize the $row['']; bit when I include the file this way.
However, if I just include this file seperately and forget the function, it works ok, obviously I replace $date with start or end inside the include file.
I know it's not the problem with the $date variable, because I can echo it fine - but when combined with the $row[''] I get problems.
Any ideas?
Cheers,
Chris