jwk811 Posted November 21, 2006 Share Posted November 21, 2006 heres a piece of code that takes info from a database and puts it as a selected option on a select form.. i dont understand how this works though.. heres the code below: and its to show currency thats being selected.. id is 1.2.3...... code is USA.. EUR....[code]$sql = "SELECT cy_id, cy_code FROM tbl_currency ORDER BY cy_code";$result = dbQuery($sql);$currency = '';while ($row = dbFetchAssoc($result)) { extract($row); $currency .= "<option value=\"$cy_id\""; if ($cy_id == $sc_currency) { $currency .= " selected"; } $currency .= ">$cy_code</option>\r\n";}[/code]thanks for the help! and dont worry about the functions they're correct but just simplifiedand the form looks just like this:<select name="cboCurrency" id="cboCurrency" class="box"><?php echo $currency; ?> </select> Quote Link to comment Share on other sites More sharing options...
jwk811 Posted November 21, 2006 Author Share Posted November 21, 2006 would there be an easier, more simpler way i could do this? or should i just stick to this code Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 21, 2006 Share Posted November 21, 2006 [quote author=jwk811 link=topic=115699.msg471135#msg471135 date=1164068323]would there be an easier, more simpler way i could do this? or should i just stick to this code[/quote]That's as simple as flexible code can be. If it ain't broke, don't fix it. Quote Link to comment Share on other sites More sharing options...
Stooney Posted November 21, 2006 Share Posted November 21, 2006 here's a small bit of something related, might help[code]<?php$pages = array("Home" => "home.html", "About" => "about.html", "Crew" => "crew.html");foreach($pages as $key => $value) echo '<option value="'.$key.'">'.$value.'</option>';?>[/code] 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.