|
Posted by Tyrone Slothrop on 10/12/91 11:29
On Sat, 15 Oct 2005 14:49:47 +0200, none <""neri\"@(none)"> wrote:
>As i said... I have several calls to the same "action" which i guess
>could be resolved as a function: but i'm learning and i have no idea how
>to do that.
>
>I post the code, extremely boring i suppose. It's in italian, but it
>shouldnt make such a difference, right?
>
>The idea is that of making a form where the select options are taken
>straight out of a mysql table, actually, a single column.
>
You can do something like this:
function options ($table, $field) {
$qy = "SELECT $field FROM $table";
$rs = mysql_query ($qy) or die (mysql_error());
while ($r = mysql_fetch_array($rs)) { ?>
<option value="<?=$r[0]?>">$r[0]?></option>
?> }
}
This way you can just pass the field and table to the function and
display the results for all of your options.
[Back to original message]
|