daGrevis Posted September 17, 2010 Report Share Posted September 17, 2010 Sveiki atkal -.-, Pēc profila labošanas, vietās, kur tiek izmantots "select" tags ar daudziem "option" vajag kaut kā izcelt pareizo "option", lai pēc atkārtotas profila labošanas nepārglabājās pāri "default'ais" "option's". =) Nu lūk - "selected='selected'", bet mana metode, lūk... <select name='gender'> <option>---</option> <option <? if($database['gender'] === 'male') { echo "selected='selected'"; } ?> value='male'>Male</option> <option <? if($database['gender'] === 'female') { echo "selected='selected'"; } ?> value='female'>Female</option> </select> Viss jau būtu okej, ja ir ~3 "option'i", bet es iedomājos, kas notiek, ja ir, piemēram, valstu saraksts (~ 250 "option'i")! Pie katra rakstīt "if()"? Nav kāds cits variants? Quote Link to comment Share on other sites More sharing options...
briedis Posted September 17, 2010 Report Share Posted September 17, 2010 un 250 ierakstu sarakstu tu raksti ar roku? Masīvs, foreach un if - ļoti labi kopā draudzējas. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted September 17, 2010 Author Report Share Posted September 17, 2010 Nu es viņu pirms tam biju uzģenerējis. =P Quote Link to comment Share on other sites More sharing options...
mad182 Posted September 17, 2010 Report Share Posted September 17, 2010 Nu manuprāt tās valstis būtu loģiski glabāt atsevišķā tabulā, un pie lietotaja glabāt tikai valsts id. Un tad arī iekš cikla, kas viņas izdrukā, varēsi salīdzināt valsts id un lietotāja saglabāto valsti. Quote Link to comment Share on other sites More sharing options...
yeahz Posted September 17, 2010 Report Share Posted September 17, 2010 <select name="country" id="country"> <option value="none">Select Country</option> <?php $countries = mysql_query("SELECT * FROM countrylist ORDER BY id asc"); while ($row = mysql_fetch_array($countries)) { if (isset($_POST['country']) && $_POST['country'] == $row['id']) echo "<option value='$row[id]' selected>$row[name]</option>"; else echo "<option value='$row[id]'>$row[name]</option>"; } ?> </select> 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.