genista Posted August 14, 2006 Share Posted August 14, 2006 Hi all,I have a script to allow a user to update their details and I am stuck with pulling back the year part of the date of birth method I am using. In order to retrieve the day I use:[code=php:0] $dbday=$row['dbday']; $dbmonth=$row['dbmonth']; $dbyear=$row['dbyear'];$currentValue = $row['dbday']; //generate drop down for day echo '<select name="dbday">'; for ($i=1; $i < 32; $i++) { //adds a leading zero if needed //$lz = strlen($i) == 1 ? '0'.$i : $i; $lz = str_pad($i, 2, '0', STR_PAD_LEFT); // check if the value displayed is the one currenlty selected $checkedStatus = ''; if ($i == $currentValue) { $checkedStatus = 'SELECTED'; } echo '<option value="'.$lz.'" '.$checkedStatus.'>'.$lz.'</option>'; } echo '</select>'; [/code]This works great. However trying to do something similar for the year doesnt work:[code=php:0]//year$currentvalue3 = $row['dbyear'];echo '<select name="dbyear">'; for ($i=1900; $i < 2006; $i++){ //adds a leading zero if needed $lz = strlen($i) == 1 ? '0'.$i : $i; $checkedStatus = '';if ($i == $currentValue3) { $checkedStatus = 'SELECTED'; } echo '<option value="'.$lz.'" '.$checkedStatus.'>'.$lz.'</option>';[/code]Any ideas as I have been looking at this all morning...Thanks,G Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/ Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 Define "doesn't work". Have you looked at the generated html code that the script produces? Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/#findComment-74433 Share on other sites More sharing options...
genista Posted August 14, 2006 Author Share Posted August 14, 2006 The html posts 1900, when I change it to say 1970 it defaulst back. Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/#findComment-74442 Share on other sites More sharing options...
genista Posted August 14, 2006 Author Share Posted August 14, 2006 Ok,I have removed the first leading zero, as it wasn't necessary, the problem is it is still not displaying the date off this code:[code=php:0]$currentvalue3 = $row['dbyear'];echo '<select name="dbyear">'; for ($i=1900; $i < 2006; $i++){ //adds a leading zero if needed $lz = strlen($i) == 1 ? '0'.$i : $i; $checkedStatus = '';if ($i == $currentValue3) { $checkedStatus = 'SELECTED'; } echo '<option value='.$checkedStatus.'>'.$lz.'</option>'; //echo '<option value="'.$lz.'" '.$checkedStatus.'>'.$lz.'</option>'; } echo '</select>'; [/code]Thanks,G Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/#findComment-74475 Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 [code]echo '<select name="dbyear">'; for ($i=1900; $i < 2006; $i++){ $checkedStatus = '';if ($i == $currentValue3) { $checkedStatus = 'SELECTED'; } echo '<option value="'. $lz. '" selected=".$checkedStatus.'">'.$lz.'</option>';} echo '</select>'; [/code] Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/#findComment-74482 Share on other sites More sharing options...
genista Posted August 14, 2006 Author Share Posted August 14, 2006 Thanks AndyBBut that line:[code=php:0]echo '<option value="'. $lz. '" selected=".$checkedStatus.'">'.$lz.'</option>';[/code]Gives me the following error: parse error, unexpected '\"', expecting ',' or ';'Taking ou some of the marks still leaves me with the list being populated with '12'. Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/#findComment-74488 Share on other sites More sharing options...
AndyB Posted August 14, 2006 Share Posted August 14, 2006 My fault - too much speed, not enough coffee. This works:[code]echo '<select name="dbyear">'; for ($i=1900; $i < 2006; $i++){ $checkedStatus = '';if ($i == $currentValue3) { $checkedStatus = 'SELECTED'; } echo '<option value="'. $i. '" selected="'. $checkedStatus. '">'. $i.'</option>';} echo '</select>'; [/code] Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/#findComment-74495 Share on other sites More sharing options...
genista Posted August 14, 2006 Author Share Posted August 14, 2006 Ok, I have solved the problem, it was a capital V in currentvalue that was causing the problem. Link to comment https://forums.phpfreaks.com/topic/17491-retrieve-problem/#findComment-74499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.