如何设置表单的DB代码 [英] How to set up DB codes for forms

查看:84
本文介绍了如何设置表单的DB代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含39个复选框的页面。我的示例中的复选框类似于表单名称。我的问题是,有39个复选框,我需要一种方式来存储给学生的形式。目前我设置的是每个表单用逗号和报价分隔,以便在运行报表时,管理员可以使用CSV下载选项并分组学生收到的表单。这工作,但是非常初步,也给一个坏的副作用,每个窗体名称之前a / is存在,因为mysql转义引号。

I have a page that has 39 check boxes. The check boxes in my example resemble form names. My problem is that with 39 check boxes I need a way to store what forms were given to a student. Currently what I have set up is that each form is separated with a comma and a quote so that when a report is run the Administrator can use a CSV download option and group which forms a student has received. This works but is very rudimentary and also gives a bad side affect that before each form name a / is present because mysql escapes quotes.

这是我目前拥有的:

 if ($this->input->post('action') == 'additional') {
     $givenforms = "";

     foreach ($this->input->post('form') as $forms) {
      $givenforms .= ', "' . $forms . '"';
        }
        $comments = 'This student was given' . $givenforms . '';

        if (($this->input->post('action') == 'additional') && ($this->input->post('other') == 'OTHER')) {
            $comments .= ', '.$this->input->post('counselorcomments');
        }
 }

再次在数据库中,结果如下:学生被给予xyz,eoe,wwo,

Again in the database the results will look like : This student was given "xyz", "eoe", "wwo",

很多,我只需要关于如何存储学生的表格,如果所有39个表格都交给学生,我需要存储学生的所有表格,以备以后报告。 (即使没有给出39个表单)

Pretty much I just need ideas on how to store which forms a student was given, and if needed if all 39 forms are given to a student I need to store all forms the student was given for later reporting. (even though 39 forms wont be given)

推荐答案

一两个小时, 。我非常非常高兴知道信息的报告/分析的可能性,以及我现在的存储方式。

An hour or two of refactoring what I had with the CSV paid off quite well. I am very very pleased with the reporting/analytical possibilities of the knew information and the way I got it stored now.

对任何一个人来说,这样的东西! :

Couple snippets of code for any one else looking into doing something like this! :

 if ($this->form_validation->run() == FALSE) { // This stuff is self explanatory RT(F)M if you will :) 
     $this->cont();
 } else {
     $this->load->model('queue_model'); // Load model

     $session = $this->uri->segment(3); // Gets the session id 
     $counselor = $this->session->userdata('username'); // I get counsellor names from the username they log in by joining between the two tables

      if ($this->input->post('action') == 'Additional') { // If additional forms is checked do the following 

      foreach ($this->input->post('form') as $form_id) { // for each form submitted take the session Id from above and insert it into the table forms with the foreach $form_id variable
          $this->queue_model->forms($session, $form_id);
      }

      if (($this->input->post('action') == 'Additional') && ($this->input->post('addother') == 'addotherinfo')) { // If forms were submitted and a addotherinfo was [checked] add comments 
          $comments = ''.$this->input->post('action'). ' - '.$this->input->post('counselorcomments').'';
      } else {
          $comments = $this->input->post('action');
      }
}  

同时在表格中添加表单名称)允许我动态地使复选框像这样:

Also adding in a forms table (with the ID's and form names) allowed me to dynamically make the check boxes like so :

<?php 
        foreach ($elevennine as $form) { ?>
              <label id="form"><input type="checkbox" name="form[]" value="<?php echo $form['form_id'] ?>" <?php echo set_checkbox('form', $form['form_id']) ?>><?php echo $form['forms'] ?></label>
<?php   } 
?>

感谢所有伟大的想法!

这篇关于如何设置表单的DB代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆