开发者

How to assign database value in Dropdownlist dynamically?

I am new in zend Framework. And i want to assign database value in dropdownlist dynamically.

Can i have any example url?I have tried to find the solution but didn't get any answer.

Please H开发者_如何学Pythonelp me...

Thanks in advance.


It sounds like you want to have a form with a element that get's it's 's from a database table.

Hopefully you are using Zend_Form, and Zend_DB_Table. You can get the values you need from a Zend_Db_Select and put them into an array.

Then create a Zend_Form with a Zend_Form_Element_Select element and use the addMultiOptions method to add your array as the select options for the element.


I don't know if there's zend syntax for DB calls, but a straight php/db call would be something akin to this:

$connect =  mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

$query = "SELECT db_Value FROM db";
$result = mysql_query($query, $connect);

while($row = mysql_fetch_array($result))
    {
echo "<input type='checkbox' id='".$row['db_Value']."'/>
<label for='".$row['db_Value']."'>".$row['db_Value']."</label>";
 }

That's dry coded, possibly glaring errors. It'll query your database for X value and continue to assign options as long as rows exist. Is that what you needed?


In Zend Framework you do it the same way as usual:

  1. retrieve the values from the database (model query)
  2. loop over the values and add them to the Zend_Navigation_Multiselect element
  3. add the element to your form
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜