|
Posted by sdk on 03/31/06 10:18
define ("SELECTALL", "SELECT * FROM `%s` ");
define ("SELECTBOX", "\n<select name=\"%s\">\n%s\n</select>\n");
define ("OPTION", "\n<option value=\"%s\">\n%s\n</option>");
define ("OPTIONSEL", "\n<option value=\"%s\"
selected>\n%s\n</option>\n");
....
function selectbox($sometable,$selected=NULL)
{
$query=sprintf(SELECTALL,$sometable);
$result = mysql_query($query);
while ($row = mysql_fetch_row($result))
{
if($row[0] != $selected)
{
$output .= sprintf( OPTION,$row[0],$row[0]);
}
else
{
$output.=sprintf(OPTIONSEL,$row[0],$row[0]);
}
}
return sprintf(SELECTBOX,$table,$output);
}
usage:
<? selectbox("firstnames","john"); ?>
would produce a selectbox with john selected.
[Back to original message]
|