Jump to content


Photo

Retrieve Problem


  • Please log in to reply
7 replies to this topic

#1 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 August 2006 - 10:50 AM

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:

 $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>'; 

This works great. However trying to do something similar for the year doesnt work:

//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>';

Any ideas as I have been looking at this all morning...

Thanks,

G

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 August 2006 - 12:12 PM

Define "doesn't work". Have you looked at the generated html code that the script produces?
Legend has it that reading the manual never killed anyone.
My site

#3 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 August 2006 - 12:44 PM

The html posts 1900, when I change it to say 1970 it defaulst back.

#4 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 August 2006 - 02:06 PM

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:

$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>';  

Thanks,
G

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 August 2006 - 02:16 PM

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>';
 
Legend has it that reading the manual never killed anyone.
My site

#6 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 August 2006 - 02:30 PM

Thanks AndyB

But that line:
echo '<option value="'. $lz. '" selected=".$checkedStatus.'">'.$lz.'</option>';

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'.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 August 2006 - 02:48 PM

My fault - too much speed, not enough coffee. This works:

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>';

Legend has it that reading the manual never killed anyone.
My site

#8 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 14 August 2006 - 02:59 PM

Ok, I have solved the problem, it was a capital V in currentvalue that was causing the problem.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users