Database connection problem/displaying combo box

I am trying to connect to my database, get the rows called task/taskid for the value and output it in a combo box.


require_once('db_fns.php');

function get_task_list(){

$conn = db_connect();

    $result = $conn->query("select * from tasks");

    while ($row = $result->fetch_assoc($result)) {

                  unset($id, $name);

                  $id = $row['id'];

                  $name = $row['task_name'];

                  echo '<option value="'.$id.'">'.$name.'</option>';

}


//db_fns.php

<?php

function db_connect() {
   $result = new mysqli('localhost', 'username', 'pass', 'table');
   if (!$result) {
     throw new Exception('Could not connect to database server');
   } else {
     return $result;
   }
}

?>

//output from my output file

function do_task_list() {
?>
   <select name="task" id="tid">';
       <? get_task_list(); ?>
   </select>
   <input type="submit" value="Submit" />
<?
}



This just outputs a blank box, and ideas/suggestions? If i don’t do it the OOP route, and do it the standard scripting all in one file it works… Please help!

Thanks,
Aaron

i just overlooked that on php.net! thanks for your help

Since you’re using the OOP style, have you tried changing

while ($row = $result->fetch_assoc($result))
to
while ($row = $result->fetch_assoc())?
Passing the result is needed in procedural code, but not OOP, since you’re calling the method of the result object that was returned by your query.