mysql - Convert two inputs to a single array to input into db codeigniter -


im busy creating webpage issues drawings client , creates receipt sending client. part i'm having trouble select drawings want add receipt , change revision.

the information drawings split on 2 tables. first contains drawing number, title, drawn etc , second contains revision history. tables linked drawing id.

to issue drawings user must tick checkboxes , change revision of drawings wants issue.

i want input database, i'm not sure how create array. controller takes gets dropdown inputs , ticked checkboxes. want dropdown inputs associated selected checkboxes updated database.

this view.

<h1>issue drawing</h1> <br>  <div id="body"> <div class="row">         <div class="form-group-sm"><lable class="col-sm-2 control-label">project number:</lable>     <?php         $js = 'onchange="this.form.submit()" class="form-control" id="focusinput"';         echo form_open('dwg_issue/issue_dwg');         echo "<div class=\"col-xs-2\">" . form_dropdown('project_no',$proj_num, $this->input->post('project_no'), $js)."</div>";         echo form_error('project_no', '<div class="col-xs-4"><div class="alert alert-danger fade in"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>','</div></div>');     ?>         </div>         </div>          <?php             echo "<noscript>".form_submit('submit','submit')."</noscript>";             echo form_close();         ?>     <form action="<?php echo base_url() . 'index.php/dwg_issue/issue'; ?>" method="post" accept-charset="utf-8" id="issue">          <table title="client information" class="table table-hover">             <caption><b>list of drawings</b></caption>         <thead>             <tr><th>project number</th><th>drawing number</th><th>client drawing number</th>                 <th>title</th><th>drawn by</th><th>revision</th><th>drawn date</th><th>select</th>         </thead>             <tbody> &nbsp;         <?php  //          var_dump($client_info);             if(!empty($result))             {                 foreach($result $row)                 {                      echo "<tr>";                     echo "<td>" . $row->project_no . "</td>";                     echo "<td>" . $row->sws_dwg_no . "</td>";                     echo "<td>" . $row->client_dwg_no . "</td>";                     echo "<td>" . $row->dwg_title . "</td>";                     echo "<td>" . $row->dwg_by . "</td>";                     $rev = array('0' => $row->dwg_rev);                     $rev_change = array(                         'b' => 'b',                         'c' => 'c',                         'd' => 'd',                         'e' => 'e'                                           );                     $dropdown = array_merge($rev,$rev_change);                      echo "<td>" . form_dropdown('dwg_rev['.$row->dwg_id.']',$dropdown) . "</td>";                     echo "<td>" . date('y/m/d', strtotime($row->dwg_date)) . "</td>";                      echo "<td>" . form_checkbox('select['.$row->dwg_id.']',$row->dwg_id) . "</td>";                      echo "</tr>";                 }             }          ?>         </tbody>        </table>         <div class="row">        <div class="col-xs-12 col-md-10">please select client distribution here other options</div>         <?php         echo "<div class=\"col-xs-6 col-md-2\"><button class=\"btn btn-md btn-primary btn-block\" type=\"submit\" form=\"issue\">issue drawings</button></div>";         ?>         </div>         <br>           <?php         echo form_close();         ?>  </div> 

my controller

public function issue_dwg() {     $data['proj_num'] = $this->model_proj->proj_num_all();     if ($this->input->post('project_no') != '0')     {         $data['result'] = $this->model_issue->list_dwg($this->input->post('project_no'));     }      $data['main_content'] = 'issue_view';     $this->load->view('includes/template.php', $data);   }  //this function takes selected drawings , create , issue slip public function issue() {     $rows = array();      $num_results = count($this->input->post('select'));     for($i = 0; $i < $num_results; $i++)     {         $rows[$i]['select'] = $_post['select'][$i];         $rows[$i]['dwg_rev'] = $_post['dwg_rev'][$i];     }    } 

the issue_dwg() function gets populates dropdown drawing numbers , populates view db results.

the issue() function needs process posted information , convert array pass db.

(i wanted add image of view page, don't have enough reputation it)

when parse form, need build inputs that, when submit form, end associative arrays:

currently have following:

//... echo form_dropdown('dwg_rev['.$row->dwg_id.']',$dropdown); echo form_checkbox('select['.$row->dwg_id.']',$row->dwg_id); //... 

when submitted, send following post array:

"select" (array)[    0 => "some select value",    1 => "some select value" ], "dwg_rev" (array)[    0 => "some dwg_rev value",    1 => "some dwg_rev value" ] 

solution:

structure form this:

//... echo form_dropdown('result['.$row->dwg_id.'][dwg_rev]',$dropdown); echo form_checkbox('result['.$row->dwg_id.'][select]',$row->dwg_id); //... 

this way, youll end array such:

"result"[    0 => [       "select" => "some select value",       "dwg_rev" => "some dwg_rev value"     ]    1 => [       "select" => "some select value",       "dwg_rev" => "some dwg_rev value"     ] ] 

now can iterate foreach in controller ease.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -