如何在嵌入php的html表中为每一行添加复选框,并在数据库(Postgresql)中更新其值
How to add checkbox for each row in table html with php embedded and update its value in database(Postgresql)?
我已经从数据库中获取了记录。它显示在html表上。但它仍然是不可编辑的模式。我想确保显示的记录完全正确,并在数据库中更新其布尔值。否则,应显示为未经批准的红色,即不正确。也许这很容易。但请帮我解决这个问题共享我的代码。
<div class="login-signup-head">Edit Table</div>
<table>
<tbody>
<thead>
<tr class="tredit">
<!-- <th width="10"></th> -->
<th contenteditable="true"> Id </th>
<th contenteditable="true"> University Id </th>
<th contenteditable="true"> Name </th>
<th contenteditable="true"> College Id </th>
<th width="100"> </th>
</tr>
</thead>
<tbody>
<?php
foreach($student_data as $row){
?>
<tr class="tredit">
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['university_id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['college_id']; ?></td>
<td><input type='button' class='editable' onclick="table_edit()" value='Edit'/>
<input type='button' class='tabledelete' onclick="table_update()" value='Delete'></td>
</tr>
<?php
}
?>
</div>
</div>
</div>
<!-- </form> -->
</div>
</div>
</tbody>
</table>
上面的代码是在控制器类中的函数的帮助下调用的,其代码如下:
public function tableedit(){
if($this->session->userdata('university_id')){
/*if($this->input->server("REQUEST_METHOD") === "POST"){*/
// $data['user_id'] = $this->session->userdata('university_id');
/*$data['name'] = $this->input->post('college_name');
$data['college_id'] =$this->input->post('college_id');
$insert = $this->home_model->addCollege($data);
$data['success'] = 'college added successfully';
}*/
$user_id = $this->session->userdata('university_id');
$data['user_id'] = $user_id;
$data['student_data'] = $this->home_model->table_data($user_id);
$this->load->view('home/new-header',$data);
// $data['get_social'] = $this->home_model->get_social();*/
// $this->load->view('socail', $data);
// if (isset($_POST['id'])) {
// echo json_encode($response);
// }
/*$this->home_model->update_university_password($user_id,$password);*/
$this->load->view('home/left_university_sidebar',$data);
$this->load->view('edit_table',$data);
$this->load->view('home/footer');
} else {
$data['error'] = 'Table Cannot be viewed!';
$this->load->view('home/header');
$this->load->view('edit_table');
$this->load->view('home/footer');
}
}
现在,上面的代码在模型类中被调用,即在哪里调用查询。
public function table_data($user_id) {
$this->db->select('id,university_id,name,college_id');
/*$this->db->where('university_id',trim($user_id));*/
$this->db->from('college');
$query = $this->db->get();
return $query->result_array();
/* $query = $this->db->query("SELECT id,university_id,name,college_id FROM college");
$this->db->where('user_id',$university_id);
return $query->result_array();*/
}
公平地说,这是一个奇怪的问题,我们无法为您编写代码。
但在您的视图中,您需要将表放入表单中,然后添加一个表单元格来包含复选框。
如何生成复选框取决于您,您可以使用CI form_helper,也可以只对引导复选框进行编码,或者使用纯html复选框。您可以这样设置复选框的值:
<input type="checkbox" name="my_value[]" value="<?php echo $entry_id; ?>">
其中entry-id是您设置的行id或标识符。你收集你的输入像这个
$my_data = $this->input->post('my_value');
现在,您有了一个包含所有检查值的数组。浏览这些内容,做任何你想做的事。
至于用红色显示不符合特定条件的项目,视图中的一个简单if语句可以做到这一点,要么显示一段完全不同的HTML,要么设置一个类用于行、表单元格或文本。
我希望这在某种程度上有所帮助,但你的问题一开始就很模糊。
祝你的网站好运,
最美好的祝愿,
保罗。
相关文章:
- 拆分文本以每隔n个字符添加一行新行,并注意空格
- 如何在jquery菜单中的li项下添加一行
- 使用 javascript 在表中动态添加一行,模糊表中的最后一行
- 如何向 Javascript 表添加一行,其中包含包含 jQuery 中的日期选择器函数的单元格
- SVG - 使用 Javascript 添加一行
- 当我添加一行时无法阻止表单提交
- 试图让JavaScript触发PHP脚本向表中添加一行,但它'It’不起作用
- 在用slim编写的ruby站点中添加一行javascript
- javascript如何每隔四个单元格添加一行
- 如何添加一行新的文本框并下拉
- 在表的每行之后添加一行
- 我如何添加一行到HTML表单
- 使用UJS动态地向表中添加一行
- jqGrid,如何通过模态形式在网格内的任何位置添加一行
- 如何添加一行代码来帮助调试Javascript
- 如果出现警告框,我不希望向表中添加一行
- Javascript在添加一行代码时会崩溃
- Spring MVC向JSP动态添加一行.javascript Vs控制器
- 使用slideDown()向jquery数据表添加一行
- js:在凸出的文本上添加一行