repopulating dropdownlist for updating in zend

  • Topic Is Locked
  • 431 Views
  • Last Post 15 July 2015
ps1907 posted this 15 July 2015

I have an address dairy project where user can add,delete or update the data. Their is a field called city which is populated from city table in address dairy form.That is working fine, But when I have to edit the data of address diary from addr table as shown below the city field is populated with the cityname which is in addr table and not from city table as shown below.

I need to populated city field from city table with selected value from addr table.

The controller code is as follows:

 $request = $this->getRequest();
$code = $this->getRequest()->getPost('data');

$db = new DbAdapter(
        array(
            'driver'        => 'Pdo',
            'dsn'            => 'mysql:dbname=marketdb;host=localhost',
            'username'       => 'root',
            'password'       => 'beeline',
            )
    );

$sql = "SELECT nma_addr.*,cityname,catname FROM nma_addr,city,category WHERE code='".$code."'";
$sql.=" and city.citycode=nma_addr.citycode and category.catcode=nma_addr.catcode";

$sm = $this->getServiceLocator();
    $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
    $statement = $dbAdapter->query($sql);
    $result    = $statement->execute();
    $num=count($result);
    if($num==0)
    {
        return $this->redirect()->toRoute(NULL, array(
            'controller'=> 'nma',
            'action' => 'index'
        ));
    }
    else
    {
            $result    = $statement->execute();
            $selectData = array();
            foreach ($result as $res) {
                   $selectData[]=$res;
                 }
$form = new NmaForm($dbAdapter);
//$viewModel = new ViewModel(array('form' =>$form));
                return new ViewModel(array(
                       'selectData' => $selectData,
                       'form' =>$form,
                     ));
    }

}

And my view file is as:

<th>City:</th>
<td>

<select name="city" id="city"><option value="1"><?php echo $val['cityname'];?></option>
</select></td>
</tr>

Here in the select tag I want data form city table but selected value from addr table.How will I be able to achieve this.?

alt text

Attached Files

Oksana Serdyuk posted this 15 July 2015

This forum is for ABBYY SDK users.

Topic Is Locked

Close