My php code to populate drop downs look like this:

<head>
<title>STOCKINSERT</title>
<?php session_start();
 $conn = new mysqli('localhost', 'root', 's', 'smv') or die ('Cannot connect to db');
 $result = $conn->query("select code, name from itemname");
 $hvo = $conn->query("select code, name from hvomaster where TYPE=1");
 $spoke = $conn->query("select code, name from hvomaster where TYPE=3");
?>
</head>

The HTML to show drop down does not show any thing

<span style="font-weight: bold;">
High volume Outlet 
</span>
</td>
<td>
<p><font size="+1"><select name="id">
<?
php session_start(); 
while ($row = $hvo->fetch_assoc()) 
    {
                  unset($id, $name);
                  $id = $row['code'];
                  $name = $row['name']; 
                  echo '<option value="'.$id.'">'.$name.'</option>';
    }
?>
</select>
</font>
</p>
</td>

But the HTMl to show this drop down works :

<td style="vertical-align: top; width: 392px; text-align: center; height: 80px; font-family: Arial Narrow;"><p><font size="+1">
<select name="id">
<?php session_start(); 
while ($row = $result->fetch_assoc()) 
    {
                  unset($id, $name);
                  $id = $row['code'];
                  $name = $row['name']; 
                  echo '<option value="'.$id.'">'.$name.'</option>';
    }
?></select></font></p></td>

What is wrong ? Please help

The simple stuff first: Does this
"select code, name from hvomaster where TYPE=1"
actually return a populated result set? I.e. is there data to put into the drop down?

Hericles, yes it does, as does type=2. Any clue ?

Not sure if this is the solution but I found this on SOClick Here

This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.

Maybe worth a go.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.