0

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

Edited by Sahishnu

2
Contributors
3
Replies
22
Views
2 Years
Discussion Span
Last Post by hericles
0

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?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.