Select Boxes

Permalink
I'm trying to build a block which in add and edit mode shows a select box which takes book titles from the controller's table and displays the relevant database field data in view mode.

The select box is working but when I select something in add or edit mode view simply displays nothing.

the code to get the title values from the table

public function getTitles(){
      $db = loader::db();
      $res = $db -> Execute('select title from btBookInfo');
      $titles = array();
      foreach($res as $row)
      {
         $titles[] = $row['title'];
      }
      return $titles;
   }


the code to display the selection box

<?php $titles = $controller -> getTitles() ?>
   <?php echo $form-> label('title', 'Title') ?>
   <?php echo $form->select('title', $titles) ?>
...


Code for view.php

<?php defined('C5_EXECUTE') or die(_("Access Denied.")) ?>
<h5><?php echo ("Title: ") ?></h5>
<?php echo ($title) ?>
<br />
<h5><?php echo ("ISBN: ") ?></h5>
<?php echo ($isbn) ?>
<hr />
<h5> <?php echo ("Description:") ?></h5>
<br />
<?php echo($description) ?>