我有一个PHP脚本来填充下拉菜单,其中包含从数据库获得的结果我遇到的问题是只有最后一个结果显示在下拉菜单中.我重新调试是因为获取所有结果的while循环会覆盖每次运行时存储字符串的变量.
我试图找到一个解决方案来解决它,但最终在一个没有解决方案的黑暗角落
PHP代码:
$sql2 = "SELECT id, course, location FROM courses WHERE course LIKE '%Forex%' OR course LIKE '%forex%'";
$query2 = mysqli_query($link, $sql2);
$opt = '';
$opt1 = 'Select Forex Workshop';
while($result2 = mysqli_fetch_assoc($query2)){
//I belief the $opt2 variable is overwritten every time the loop runs
$opt2 = ''.$result2['course'].'';
print_r($opt2);
}
$opt3 = '';
return $opt.$opt1.$opt2.$opt3;
}
我可能是错的,问题可能在代码中的地方但是当我print_r($result2)所有正确的结果都在那里