I use a function for generating select menus:
function getsqlselect($selname, $sql, $mark="", $nul=false, $onchange=false)
{
if($onchange)
$odazu = " onChange=\"submit()\"";
$qsel = db_query($sql);
$sel = "<select name=$selname size=1$odazu>\n";
if($nul)
$sel .= " <option value=0></option>\n";
for($i=0; $i < count($qsel); $i++)
{
$satz = $qsel[$i];
if($satz[1] == "") $satz[1] = $satz[0];
if($mark != "" && $satz[0] == $mark)
$dazwischen = " selected";
else
$dazwischen = "";
$sel .= " <option value=\"".$satz[0]."\"".$dazwischen.">".dirt($satz[1])."</option>\n";
}
$sel .= "</select>\n";
return $sel;
}
but let me explain:
- this function uses an db abstraction function named db_query. you give it an sql select statement, it returns a 2-dim array (1 record per element, each record consisting of n fields) you'll have to insert your own db query code here.
- it expects an sql statement like:
select id,name from persons where ...
(first field is the option value, second the "nice" name)
- selname = the html name that will be given to the select menu
- mark = the value that will be marked as selected
- nul: if set true, an empty option will be inserted above the others: <option value=0></option>
- onChange: inserts onChange=submit(), if set true
regarding record display:
you put such a select on a html page in a form. when submitted, a second php script generates a html page which displays the record that has eben selected in the select menu.
you've given the select a $selname, say id_person.
in the script that's now being called, build this variable into your select statement, and execute:
$sql = "select * from person where id=$id_person";
now display this data in a table, or whatever, done!
if you're new to php, try to understand the code, experiment a bit ...