...

View Full Version : Using select to update profile...



Jer
10-20-2010, 01:12 AM
$userdata = mysql_query("SELECT * FROM user_data WHERE id='$id'");
$row = mysql_fetch_array($userdata);

$timezone=$row['time_zone'];

That pulls an int to relate to my timezone table.



print "<select name='' style='width: 157px'>";
$sql = mysql_query("SELECT * FROM timezone");
while ($row = mysql_fetch_array($sql)) {
print "<option value={$row['timezone_id']}>{row['timezone_name']}</option>";
}
print "</select>";

I have no errors and the list populates correctly.

What I want it to do is show the option as the original value in the <select> coding. So if my user has record 24 which is EST+5GMT that is what option is shown already selected in that box. This is for an edit page of a user profile.

Apologies I'm trying to do this on a phone since I'm at work.

abduraooft
10-20-2010, 09:58 AM
Change
while ($row = mysql_fetch_array($sql)) {
print "<option value={$row['timezone_id']}>{row['timezone_name']}</option>";
} to

while ($row = mysql_fetch_array($sql)) {

printf( "<option value={$row['timezone_id']} %s>{row['timezone_name']}</option>",
($row['time_zone']==$row['timezone_id']?'selected="selected"':''));
}

Jer
10-20-2010, 04:38 PM
Still didn't select properly, but you may have pointed me in the correct direction.

Jer
10-20-2010, 04:42 PM
printf( "<option value={$row['timezone_id']} %s>{$row['timezone_name']}</option>",
($timezone==$row['timezone_id']?'selected="selected"':''));

Just a change in variables. Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum