0

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

1 Answer 1

3

incorrect foreach construction:

foreach ($nome as $random_variable_name) {

PS: Try to turn on error reporting while developing.

Sign up to request clarification or add additional context in comments.

4 Comments

True, but reasonably safe to assume that because the echo line of that foreach is obviously written for example that perhaps the actual foreach syntax would be OK too? OP should definitely have posted proper code though.
OK - after his edit I can see you happen to be correct
I will turn on error reporting. that is done from php.ini. Right? thank you and sorry for the stupid question. after whole day I was too tired to notice that.
@user3384514 You can also set it at runtime (preferably distinguish with an if if you are in developing or production mode) ... php.net/manual/en/function.ini-set.php

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.