如何将数据库中的数据存储在数组中以供进一步使用

I am doing a database and i fetch my data like this:

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);

my print_r show an array like associative array. I need to do a foreach to fill my option box

foreach $nome as $random_variable_name {
 echo ......fill textbox here
}

but i Always get a blank page. what i don't get EDIT CODE IN HTML

    <option value="" disabled="disabled" selected="selected">Scegli una categoria</option>
     <?php foreach($nome) as ($sceltacategoria) {
   echo '<option value="1"> '.$sceltacategoria.'</option>';}
   ?>
</select>

EDIT 2 When i print array with print_r it show me that like this :

Array([0]=>1rstfield [1]=> ) ecc

查看全部
doujuan9698
doujuan9698
2014/03/06 23:51
  • php
  • mysql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复