Forum Moderators: coopster
select date_format(yourfield,"%Y"), date_format(yourfield,"%m"), date_format(yourfield,"%d") from users where user_id=1234;
while ($row=mysql_fetchrow_array)) {
// Remembering fetchrow_array returns BOTH indexed and
// associative array, you don't need "select field as..."
$year = $row[0];
$month = $row[1];
$day = $row[2];
}
// Defined these as constants so you don't have to use globals
// you may want to get the end year dynamically so it's always
// this year, requiring no maintenance
define('START_YEAR',1901);
define('END_YEAR',2011);
//
function get_date_list($name,$yyyy=null,$mm=null,$dd=null) {
$yname = $name . '_year';
$mname = $name . '_month';
$dname = $name . '_day';
$start_year = START_YEAR;
$end_year = END_YEAR;
$dtString = "
<select name=\"$mname\" id=\"$mname\">
<option value=\"\">--</option>
";
for ($i=1;$i<12;$i++) {
$moTxt = (strlen($i)<2)?"0" . $i:$i; // 01 instead of 1
$dtString .= "<option value=\"$moTxt\"";
if ($mm == $moTxt) { $dtString .= ' selected'; }
// Or selected=\"selected\" if you're using XHTML, which you most likely won't need
$dtString .= ">$moTxt</option>\n";
}
$dtString .= "
</select>
<select name=\"$dname\" id=\"$dname\">
<option value=\"\">--</option>
";
for ($i=1;$i<32;$i++) {
$daTxt = (strlen($i)<2)?"0" . $i:$i;
$dtString .= "<option value=\"$daTxt\"";
if ($dd == $daTxt) { $dtString .= ' selected'; }
$dtString .= ">$daTxt</option>\n";
}
$dtString .= "
</select>
<select name="$yname" id="$yname">
<option value=\"\">--</option>
";
for ($i$start_year;$i<=$end_year;$i++) {
$dtString .= "<option value=\"$i\"";
if ($yyyy == $i) { $dtString .= ' selected'; }
$dtString .= ">$i</option>\n";
}
$dtString .= "
</select>\n";
//
return $dtString;
} // End get_date_list()
function get_date_list($name,$yyyy=null,$mm=null,$dd=null) { // don't understand this line, function being passed these variables from where?
$yname = $name . '_year'; // not sure what these are or how they came to exist?
foreach ($datefields as $fld) {
$yy = $fld . '_year'; // startdate_year and expiredate_year
$mm = $fld . '_month'; // startdate_month and expiredate_month
$dd = $fld . '_day'; // startdate_day and expiredate_day
// Presuming you've ALREADY CLEANSED $_POST and for simplicity
if (
isset($_POST[$yy]) and ! empty($_POST[$yy])
and isset($_POST[$mm]) and ! empty($_POST[$mm])
and isset($_POST[$dd]) and ! empty($_POST[$dd])
) {
$ins = $_POST[$yy] . '-' . $_POST[$mm] . '-' . $_POST[$dd];
if ($fields) { $fields .= ','; }
$fields .= " $fld='$ins'";
}
}
//
if ($fields) {
$fields = preg_replace('/,$/','',$fields); // or use trim. :-)
$query = "update table set $fields where id=12345";
// etc.
}
foreach ($_POST as $key=>$value) {
if (preg_match('/[a-z]+\_year$/i',$key)) {
// I've found a date select list
list($name,$tag) = explode('_',$key);
$yy = $name . '_year'; // redundant, I know . . .
$mm = $name . '_month';
$dd = $name . '_day';
// proceed as above
}
}
The only thing I need to work out now is how to put it into a form and insert them into db for the in method but I thought I'd post that separately
Is that single or doubles quotes you’ve got round that. :-)
I’ve never seen code processed like this before:
the popular but difficult-to-debug drop in 'n' out of PHP,
....
Does it mean where I've enclosed the html in start and end php tags I replace them with quotes and end with a semicolon: