Note that there are some explanatory texts on larger screens.

plurals
  1. PODropdown dependent on other dropdown in php
    primarykey
    data
    text
    <p>Hey friends I am trying to make two dropdown boxes. The first one is sensor type select. The second one is sensor names and it should be dependent on the first one .I am using MVC architecture.Here is my code I am using. At the viewpage.php I have:</p> <pre><code>&lt;table&gt; &lt;td&gt; &lt;label&gt;&lt;b&gt;Sensors Types:&lt;/b&gt;&lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo form_dropdown('sensor_types', $sensor_types, '#', 'id="sensor_types" onchange="copy();" ');?&gt; &lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt; &lt;label&gt;&lt;b&gt;Sensor Name:&lt;/b&gt;&lt;/label&gt; &lt;/td&gt; &lt;td&gt; &lt;?php echo form_dropdown('sensorzs', $sensorzs, '#', 'id="sensorzs"'); ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>and the code in the model.php is</p> <pre><code>function sensors_list($node_id) { $this-&gt;db-&gt;select('sensor_index, sensor_name'); $this-&gt;db-&gt;where('node_id', $node_id); //$this-&gt;db-&gt;where('sensor_type', $sensor_types); $this-&gt;db-&gt;order_by('sensor_index'); $query = $this-&gt;db-&gt;get('node_sensor_dtl'); } function get_all_sensors($node_id) { $this-&gt;db-&gt;select('sensor_pk, sensor_name'); $this-&gt;db-&gt;where('node_id', $node_id); $this-&gt;db-&gt;order_by('sensor_index'); $query = $this-&gt;db-&gt;get('node_sensor_dtl'); $sensors = array(); if($query-&gt;result()) { $sensors[''] = '-Select-'; foreach ($query-&gt;result() as $sensor) { $sensors[$sensor-&gt;sensor_pk] = $sensor-&gt;sensor_name; } return $sensors; } else { $sensors = NULL; return $sensors; } } </code></pre> <p>and the code in the node.php the code is like this</p> <pre><code>function edit(){ if($this-&gt;CI-&gt;input-&gt;post('editform_id') == NULL) redirect('configuration/node/'); $view_data['page_title'] = "Node edit details"; $view_data['page_name'] = ""; $view_data['detail'] = $this-&gt;CI-&gt;model-&gt;get_node($this-&gt;CI-&gt;input-&gt;post('editform_id')); $view_data['sensor_types'] = $this-&gt;CI-&gt;model-&gt;get_all_sensor_types(); $view_data['sensorzs'] = $this-&gt;CI-&gt;model-&gt;sensors_list($this-&gt;CI-&gt;input-&gt;post('editform_id')); $this-&gt;CI-&gt;load-&gt;view('config_node_view', $view_data); } </code></pre> <p>I´ve tried this for past few days but could get the result. Searched lot of site and blogs but I can't get the required results. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload