English 中文(简体)
准则识别——表格_从数据库中选择正确价值
原标题:Code Igniter - form_dropdown selecting correct value from the database

在《刑法》中,在形式上存在几个问题。 我的申请分两部分,用户可以进入、进入表格并提交......一旦提交行政文件,个人就可以组成,然后将其保存到数据库。

因此,为了显示最初形式的下降,采用以下方法(下降的所有选择都来自数据库......)

模式:

    function get_salaries_dropdown()
{
    $this->db->from($this->table_name);
    $this->db->order_by( id );
    $result = $this->db->get();
    $return = array();
    if($result->num_rows() > 0){
            $return[  ] =  please select ;
        foreach($result->result_array() as $row){
            $return[$row[ id ]] = $row[ salaryrange ];
        }
    }
    return $return;
}

Then in the Controller:

$data[ salaries ] = $this->salary_expectation->get_salaries_dropdown();

随后是最后的观点:

<?php echo form_dropdown( salaries , $salaries, set_value( salaries , $salaries));  ?>

这一缩略语在显示由用户选择的数值填补的退缩方面是完美的。

因此,当用户选择一个价值时,就会发现节省费用,将其节省到数据库。

在Edit的网页上,行政部使用同一代码显示已填满的各种选择,但是,如何自动选择用户在初始阶段选择的办法?

Cheers,

最佳回答

According to Codeigniter documentation

The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value you wish to be selected. You can also pass an array of multiple items through the third parameter, and CodeIgniter will create a multiple select for you.

阁下的行政管理人员应当拥有类似的东西。

$data[ selected ] = $this->salary_expectation->get_salary_selected();

根据这一点,行政部门认为,这一点也一样。

<?php echo form_dropdown( salaries , $salaries, $selected_value);  ?>
问题回答

one nasty solution to select the <option> element of <select> generated by form_dropdown() function of the form_helper is using the post input sended. I made this because any solutions I found doesn t display the value that the user select in the form neither set_selected nor set_vaule. Well, in my controller I have:

$countries = $this->country_model->get_dropdown_array(); // The array have something like $countries[COUNTRY_ID] = COUNTRY_NAME
$data[ countries ]=$countries;

我认为:

$selected_country = $this->input->post( country );
echo form_dropdown( country ,$countries,$selected_country);

• fine!

The form_dropdown function has a third parameter for the selected option. Use it like this:

<?php echo form_dropdown( piece_type , 
        array(
             type1  =>  Firts type ,
             type2  =>  Second option 
            $selected_value, 
             id = "piece_type" ) ?>

I had the same problem but i have overcome on this problem using code igniter syntex. Here is the solution. Fisrt step Before the loop initialize two arrays

$options = array();
$select = array();

然后在假日写这一指示

foreach($result->result_array() as $row)
{
    /////////Your Condition ////////////
    if($row[ id ] == $myarray[ mycolumn ])
    {            
        $options [$row[ id ]] = $row[ salaryrange ];
        $select = $row[ id ] ; 
    }else{
        $options [$row[ id ]] = $row[ salaryrange ];
    }
}

现在

echo form_dropdown( dropdown_name  , $options , $select);

它正在工作

对于更新案件,如果通过变数与(从控制员到)员额(从控制员)一样,则你具有相应价值:

<?php echo form_dropdown( salaries , $salaries, $ind_post->salaries,  );  ?>




相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

What s the proper MVC way to do this....?

Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I m actually using Kohana). I m new to MVC and don t want to get this wrong... so I m wondering if i have ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

CodeIgniter adding semicolons

How do I stop CodeIgniter adding semicolons ; to data sent via POST that contains ampersand &? For example it is converting "a=1&b=2&c=3" into "a=1&b;=2&c;=3". From looking on the forums ...

Best way to make Admin pages in CodeIgniter?

I m working on an app in CodeIgniter, and I want to have admin pages for several of the objects in the application, and I m wondering what would be the better way to put these into an MVC structure. ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签