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>
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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