Jump to content

can someone explain this little bit of code for me?


jwk811

Recommended Posts

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 simplified

and the form looks just like this:
<select name="cboCurrency" id="cboCurrency" class="box">
<?php echo $currency; ?>
    </select>
[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.
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.