Jump to content

Profile page


arneman

Recommended Posts

 

I want to give my users a chance to change their profile. But I want the selectable date to show up in comboboxes but the data from the MySQL DB should be selected.

 

For the gender I managed to solve this with a simple IF structure. But I'm not planning on doing this 12 times for the months or even 60 times for the years.

 

I'm looking forward to hearing your ideas.

 

My current code is at : http://www.plaatscode.be/137085

Link to comment
Share on other sites

Dutch: Waarom zijn alle belgen toch zo lui? ;)

 

$months = array(1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'November', 'December');
$years = array();
$currentYear = (int) date('Y');
for ($i = $currentYear; $i > $currentYear - 100; --$i) { // sorry 100+ shouldn't surf the web 
    $years[] = $i;
}

Link to comment
Share on other sites

Are you saying that you want the month/day/year selected that is the same as the date being pulled from the db?

 

If so, just add an if to your loops that generate the select menus

 

<select name="year">
<?php
$yearfrommysql = 1975;

for($i = 1960; $i < 2040; $i++) {

if($yearfrommysql == $i) {
	echo "<option value='$i' selected='selected'>$i</option>\n";
} else {
	echo "<option value='$i'>$i</option>\n";
}
}

?>
</select>

Link to comment
Share on other sites

This 5 lines of code do the same thing your 15 lines of code do ;)

 

<select name="gender">
    <option>-</option>
    <option value="1"<?php $gender === 1 ? ' selected="selected"' : '' ?>>Male</option>
    <option value="2"<?php $gender === 2 ? ' selected="selected"' : '' ?>>Female</option>
</select>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.