Greetings,

In several scripts that I have written I have had to have a similar select
box.  It will select from a table an auto number field and a name field
(like an id # and a customer name) and then it will display the name on the
screen and the variable posted will be the auto #.

Could anyone offer any suggestions?  The following function prints a blank
select box.



function select_box($name, $table, $field, $value)
{
print "<select name=\"$name\">\n";
$result= "select auto, '$field' from '$table' order by '$field' order by
name asc";
$result= mysql_query($result);
if ($result)
{
        while ($row = mysql_fetch_array($result))
        {
                print "<option value=".$row["auto"];
                if (($value != "no") && ($value==$row["auto"]))
                {
                        print " selected";
                }
                print ">".$row[$field]."</option>\n";
        }
        mysql_free_result($result);
}
print "</select></td><td>\n";
}


Here is a working example that is not in a function:

//Get Existing Accounts and put them in a select box
print "<select name=account>\n";
$result= mysql_query("select * from ledger_accounts order by name asc");
if ($result)
{
        while ($row = mysql_fetch_array($result))
        {
                print "<option value=".$row["auto"];
                if ($account==$row["auto"])
                {
                        print " selected";
                }
                print ">".$row["name"]."</option>\n";
        }
        mysql_free_result($result);
}
print "</select></td><td>\n";



Thanks,

Leonard Burton
[EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to