【问题标题】:When input type submit is clicked, generate a query单击输入类型提交时,生成查询
【发布时间】:2021-05-22 03:37:49
【问题描述】:

这里是初学者。我目前正在制作一个匹配系统,业主将在其中注册他们的条目。完成后,我将单击“匹配”按钮,它将生成匹配。 匹配的逻辑取决于权重。

例如,如果 owner 1owner 2 注册了一个有 1900 重量的条目,他们将 自动匹配。 (如第二张表所示)

我怎样才能实现我的这些目标?提前谢谢你们。

tbl_entry

    |id| entryName| lightBand| weight  |
    |---| --------| -----    |---------|
    | 1 | owner1  |     1    |  1900   |
    | 2 | owner1  |     2    |  1920   |
    | 3 | owner2  |     3    |  1900   |
    | 4 | owner3  |     4    |  1910   |
    | 5 | owner4  |     5    |  1910   |
    
    tbl_matching
    | id  |fightID| entryName| lightBand| weight  | entryName| lightband1| weight1|
    |---- |--------| --------| -----    |---------|--------   |----------|--------|
    |  1  |   1    | owner1  |     1    |  1900   | owner2    |   3      |  1900  |   
    |  2  |   2    | owner3  |     4    |  1910   | owner4    |   5      |  1910  |
    |  3  |   -    | owner2  |    -     |    -    |   -       |   -      |   -    |

HTML:

<form action="transaction/match" method="POST">
<input type="submit" name="doMatch"> match 
</form>

控制器:

public function match {

$formSubmit = $this->input->post('doMatch');

// do the matching query here


}
  • (连字符/破折号)

【问题讨论】:

    标签: mysql codeigniter


    【解决方案1】:

    注意:我使用的是 codeigniter3。 首先,我以前从不使用&lt;input type = "submit"&gt;,通常我使用&lt;input type="text"&gt;并将提交按钮。 假设你有

    <input type="text" name="entryName">
    <input type="text" name="weight">
    ... etc
    

    你可以把它放在你的控制器中(以后,你应该使用 Control -> Model)

        $weight = $this->input->post('weight'); //get your weight input
    
        //get the opponent data based on weight input
        $result = $this->db->get_where('tbl_entry', ['weight' => $weight])->row_array();
    
        //check if the result is not null
        if ($result != null) {
            $submit = [
                 //I assume that your ID is autoincrement
                'fightID' => 'fight ID', //you can make a function for fight ID and put the result like $fight_ID
                'entryName' => $this->input->post('entryName'),
                'lightBand' => $this->input->post('lightBand'),
                'weight' => $weight,
            ];
            $data[] = array_merge($submit, $result); //merge the entry and the result into 1 array
    
            $this->db->insert('tbl_matching', $data); //insert it into your table matching
        }
        else {
          //like above, but just change it to '-' instead of input->post
        }
    

    【讨论】:

      猜你喜欢
      • 2017-08-15
      • 2013-07-17
      • 1970-01-01
      • 2012-02-06
      • 2014-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多