gpt4 book ai didi

php mysql 将结果显示为下拉列表

转载 作者:行者123 更新时间:2023-11-29 04:52:23 26 4
gpt4 key购买 nike

我非常努力地从数据库中获取结果,以显示为下拉列表。

基本上我正在获取外键、它的唯一代码和它的名称/标题。我需要将其显示为下拉列表,以便正确输入到新表中

        $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 的新手。任何帮助,将不胜感激。但是这个数组对我来说看起来毫无用处,而且我不确定如何填充列表。我获取结果/数组的文件不是我将数组填充到列表中的位置。

非常感谢有关此事的任何提示

最佳答案

假设您要做的只是将这些行回显到下拉列表中:

$sql = "SELECT quali_code, title FROM `qualifications` ORDER BY title ";
$result = mysql_query($sql, $this->connection);
while($r=mysql_fetch_array($result))
{
$quali_code = $r['quali_code'];
$result_array[$quali_code][] = $r['title'];
}


echo "<select name='x'>";
foreach($result_array as $q_code => $value)
{
foreach($value as $title) {
echo "<option value='" . $q_code . "'>" . $title . "</option>";
}
}
echo "</select>";

关于php mysql 将结果显示为下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10252307/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com