我正在努力尝试从数据库中获取结果以显示为下拉列表。
基本上我正在获取外键、它的唯一代码和它的名称/标题。我需要将其显示为下拉列表,以便正确输入到新表中
$sql = "SELECT quali_code, title FROM `qualifications` ";
$result = mysql_query($sql, $this->connection);
$result_array = array();
while($r=mysql_fetch_array($result))
{
$result_array[$r['quali_code']][] = $r;
}
return $result_array;
有了这个,我需要在 HTMl/PHP 中创建一个下拉列表来选择标题,但显然是存储值。有点<list name=array[title] value=array[code] >
目前我已经被困在一个适合我的数组中返回我的 SQl 结果,并且不知道如何使用正确的数组结果填充下拉列表。
上面的示例代码说明了我如何获取 sql 结果以及我的数组的外观:
Array ( [AAT] => Array ( [0] => Array ( [0] => AAT [quali_code] => AAT [1] => AAT qualification [title] => AAT qualification ) ) [A_lev] => Array ( [0] => Array ( [0] => A_lev [quali_code] => A_lev [1] => A levels [title] => A levels ) ) [HNC] => Array ( [0] => Array ( [0] => HNC [quali_code] => HNC [1] => Fdsc/HNC [title] => Fdsc/HNC ) ) [Lan_ISLT] => Array ( [0] => Array ( [0] => Lan_ISLT [quali_code] => Lan_ISLT [1] => EISLT Qualification [title] => EISLT Qualification ) ) [Lan_qua] => Array ( [0] => Array ( [0] => Lan_qua [quali_code] => Lan_qua [1] => Language qualification [title] => Language qualification ) ) [Nat_Dip] => Array ( [0] => Array ( [0] => Nat_Dip [quali_code] => Nat_Dip [1] => National Diploma [title] => National Diploma ) ) )
请记住,我对 PHP 完全陌生。任何帮助,将不胜感激。但是这个数组对我来说看起来没用,并且不确定如何填充列表。我获取结果/数组的文件不是我将数组填充到列表中的位置。
非常感谢您对此事的任何提示