当点击输入类型提交时,生成查询

问题描述 投票:0回答:1

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

例如,如果所有者 1所有者 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


}
  • (连字符/破折号)<<<< means no correspondent player to match with.
php mysql codeigniter
1个回答
1
投票

注意:我使用的是codeigniter3。 首先,我以前从未使用过

<input type = "submit">
,通常我使用
<input type="text">
并将提交按钮放入其中。 假设你有

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

您可以将其放入控制器中(稍后您应该使用“控制”->“模型”)

    $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
    }
© www.soinside.com 2019 - 2024. All rights reserved.