mac-in-the-mountains wrote:
> It's the %,%,2009 bit that needs to be replaced with
something that detects
> only the year contained within the MySql date field and
sets $coursefee to
> cost09 or cost10 accordingly.
It depends on how the date is being returned from MySQL. The
default
format for a date in MySQL is YYYY-MM-DD, so you can just
check the
first four digits like this:
if (substr($row_rs_dates['start_date'], 0, 4) == '2009') {
$coursefee = $row_rs_course['cost09'];
} else {
$coursefee = $row_rs_course['cost10'];
}
However, the disadvantage with this is that you're going to
need to
change your code every year. A better solution would be to
use the final
two digits of the year like this:
$year = substr($row_rs_dates['start_date'], 2, 2);
$coursefee = $row_rs_course["cost$year"];
Note that I have used double quotes for "cost$year" to ensure
that the
value of $year is substituted.
There are other solutions, particularly if you have used
DATE_FORMAT()
to format the date as it's retrieved from MySQL. For example,
you could
use DATE_FORMAT(start_date, '%y') AS theYear to extract the
final two
digits of the year from the start_date column.
--
David Powers
Adobe Community Expert, Dreamweaver
http://foundationphp.com