Zepo. Posted November 22, 2007 Share Posted November 22, 2007 Im having a problem with a form select auto selecting after it's gone through a loop. The first auto select is right, but then everyone after that is the same. $members=mysql_query("SELECT id,name,position,about,aim,website FROM members WHERE teamid='$team[id]' ORDER BY name"); while(list($id,$name,$position,$about,$aim,$website)=mysql_fetch_row($members)){ if($config[altcolorx]==$config[altcolora]){ $config[altcolorx]="$config[altcolorb]"; }else{ $config[altcolorx]="$config[altcolora]"; } $selectposition="$position"; $selected_rank[$selectposition]="SELECTED"; $out[body].=" <tr bgcolor='$config[altcolorb]'> <form method='post'> <td width='19%' valign='center' align='left'><input type='text' class='input' name='team[membername]' value='$name' size='15' maxlength='25'></td> <td width='19%' valign='center' align='left'> <select name='team[position]'> <option value='6' $selected_rank[6]>Member</option> <option value='5' $selected_rank[5]>2nd Lieutenant</option> <option value='4' $selected_rank[4]>1st Lieutenant</option> <option value='3' $selected_rank[3]>Captain</option> <option value='2' $selected_rank[2]>Co-Leader</option> <option value='1' $selected_rank[1]>Leader</option> </select></td> <td width='19%' valign='center' align='left'><input type='text' class='input' name='team[aim]' value='$aim' size='15' maxlength='15'></td> <td width='19%' valign='center' align='left'><input type='text' class='input' name='team[website]' value='$website' size='15' maxlength='35'></td></tr> <tr bgcolor='$config[altcolorb]'> <td width='70%' colspan='3' valign='center' align='left'><textarea class='button' name='team[about]' value='$about' maxlength='255' style='width:320px; height:40px;'>$about</textarea></td> <td width='30%' valign='center' align='center'> <table><tr bgcolor='$config[altcolorb]'><td width='50'> <input type='hidden' name='action' value='editmember'> <input type='hidden' name='team[memberid]' value='$id'> <input type='hidden' name='login[id]' value='$login[id]'> <input type='hidden' name='login[pass]' value='$login[pass]'> <input type='submit' name='submit' value='Update >>'></form> <form method='post'></td><td width='50'> <script language='javascript'>var confirmdelete2='Are you 100% sure you want to DELETE this member?';</script> <input type='hidden' name='action' value='deletemember'> <input type='hidden' name='team[memberid]' value='$id'> <input type='hidden' name='login[id]' value='$login[id]'> <input type='hidden' name='login[pass]' value='$login[pass]'> <input type='submit' name='submit' value='Delete >>' onClick='return confirm(confirmdelete2);'></form></td></tr></table> </td> </tr>"; $totalmembers++; } You can see a demo of what i mean: http://eliteladders.com/devlopement/manager.php user:36 pass:aaaaaa It's the member manager. Quote Link to comment Share on other sites More sharing options...
willpower Posted November 22, 2007 Share Posted November 22, 2007 sorry dude...just getting a 404 Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 22, 2007 Author Share Posted November 22, 2007 Sorry try it now... http://www.eliteladders.com/devlopment/manager.php Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 23, 2007 Author Share Posted November 23, 2007 Bumpity Bump Bump Quote Link to comment Share on other sites More sharing options...
phpSensei Posted November 23, 2007 Share Posted November 23, 2007 Your demo account can't access the member's page. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 23, 2007 Author Share Posted November 23, 2007 Sorry someone messed with it, try id 38 pass: aaaaaa. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted November 30, 2007 Author Share Posted November 30, 2007 Ummm Bump. Quote Link to comment Share on other sites More sharing options...
Zepo. Posted December 1, 2007 Author Share Posted December 1, 2007 One last try...... Quote Link to comment Share on other sites More sharing options...
marcus Posted December 1, 2007 Share Posted December 1, 2007 That's one messy code. You're better off listing the ranks in a table. $sql = "SELECT * FROM `ranks`"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ $check = ($row['id'] == $position) ? " CHECKED" : ""; echo "<option value=\"{$row['id']}\"$check>{$row['name']}</option>\n"; } Quote Link to comment Share on other sites More sharing options...
jumpfroggy Posted December 1, 2007 Share Posted December 1, 2007 The main problem is here: $selected_rank[$selectposition]="SELECTED"; This is executed every time you loop through the rows. Say the first time $selectposition is 1. So that means that $selected_rank[1] = "SELECTED", while the others are empty. Next row, $selectposition is 2. So you set $selected_rank[2] = "SELECTED", but $selected_rank[1] is also "SELECTED". If the browser sees many "SELECTED" options, it'll select the first one and leave the rest. Look at your HTML source, you probably have SELECTED's everywhere. Better: $members=mysql_query("SELECT id,name,position,about,aim,website FROM members WHERE teamid='$team[id]' ORDER BY name"); while(list($id,$name,$position,$about,$aim,$website)=mysql_fetch_row($members)){ // NOTE: We don't need the $selectedposition variable... it's the same as $position... //$selectposition="$position"; // Don't use this array //$selected_rank[$selectposition]="SELECTED"; $out[body].=" ... <select name='team[position]'> <option value='6' " . ( $position == 6 ? "SELECTED" : "" ) . " >Member</option> <option value='5' " . ( $position == 5 ? "SELECTED" : "" ) . " >2nd Lieutenant</option> ... </select> ... "; } This syntax: test_value ? return_if_true : return_if_false Is useful here. If "test_value" is true, it'll return "return_if_true". Otherwise, it'll return "return_if_false". So this: $position==6 ? "SELECTED" : "" Means check if $position is 6... if so, return "SELECTED", if not return "". Works for you? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.