我正在做一个数据库,我这样获取我的数据:
if ($db_found) {
$SQL = "SELECT mat.nome AS nome FROM materiali AS mat
JOIN campo_di_utilizzo_materiali AS cum ON cum.id_materiali=mat.idmateriali
JOIN campo_di_utilizzo as cu ON cu.idcampo_di_utilizzo=cum.id_campo GROUP BY mat.nome;";
$result = mysql_query($SQL);
$nome = array();
while ( $db_field = mysql_fetch_assoc($result) ) {
$nome[]=$db_field['nome'];
mysql_close($db_handle);
}
print_r ($nome);
我的print_r显示了一个像关联数组的数组。 我需要做一个foreach来填充我的选项框
foreach $nome as $random_variable_name {
echo ......fill textbox here
}
但我总是得到一个空白页面。我得不到的 用HTML编辑代码
<option value="" disabled="disabled" selected="selected">Scegli una categoria</option>
<?php foreach($nome) as ($sceltacategoria) {
echo '<option value="1"> '.$sceltacategoria.'</option>';}
?>
</select>
编辑2 当我使用print_r打印数组时,它向我显示如下:
数组([0] =&gt; 1rstfield [1] =&gt;)ecc
答案 0 :(得分:3)
错误的foreach构造:
foreach ($nome as $random_variable_name) {
PS:尝试在开发时打开错误报告。