根据复选框Codeigniter更新数据库

时间:2015-07-15 09:44:53

标签: php codeigniter checkbox

我尝试使用复选框更新数据库列。我的想法是,我只想在主页上显示某些内容,因此复选框应该向数据库发送0或1。如果第一页中的记录为0,则它​​不应出现在主页上,如果它有1则应该出现。

我尝试过设置一些东西,但它没有按预期工作(它只是刷新页面而没有效果)

复选框:

<?php echo form_checkbox(array('name' => 'first_page', 'class'=>'checkbox-inline', 'value' => 1)); ?>

控制器:

if(null != ($this->input->post('first_page'))) {
    $first_page = 1;
    $book_id= $this->input->post('id'); (the id is sent to the controller via an extra hidden input field)

    $this->book_model->first_page($first_page, $book_id);
}

型号:

$this->db->set ( "first_page", $first_page);
$this->db->where ( "book_id", $book_id);
$this->db->update ( "books" );
return;

完整格式:

    <?php echo form_open('admin/modifica_autor'); ?>
                <?php echo form_hidden('id', $item->id_carte); ?>
                <?php echo form_hidden('id_autor', $item->id_autor)?>
                <label for="titlu_nou">Titlu:</label>
                <?php echo form_input(array('name' => 'titlu_nou_carte', 'class'=>'form-control', 'value' => $item->titlu)); ?> <br>
                <label for="autor_nou">Autor:</label>
                <select name='autor_nous' class="form-control"><?php                                        
        foreach ( $autori2 as $row ) { 
            echo '<option value="' . $row->id_autor . '">' . $row->nume_autor . '</option>'; }
  ?></select><br>
    <label for="domeniu_nou">Domeniu:</label>
    <select name='domeniu_nou' class="form-control"><?php                                       
    foreach ( $domenii as $row ) { 
    echo '<option value="' . $row->id_domeniu . '">' . $row->nume_domeniu . '</option>';
                                            }
    ?></select><br>
   <label for="pret_nou">Pret:</label>
   <?php echo form_input(array('name' => 'pret_nou', 'class'=>'form-control', 'value' => $item->pret.' LEI')); ?><br>
  <label for="descriere_noua">Descriere:</label>
   <?php echo form_textarea(array('name' => 'descriere_noua', 'class'=>'form-control textarea', 'value' => $item->descriere)); ?><br>
   <label for="prima_pagina">Afisare pe prima pagina:</label>
   <?php echo form_checkbox(array('name' => 'prima_pagina', 'class'=>'checkbox-inline', 'value' => 1)); ?>

    </div>
   <div class="modal-footer">
   <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
 <?php echo form_submit(array('name'=>'submit_autor','value' => 'Modifica', 'class'=>'btn btn-default')); ?>
  <?php echo form_close(); ?>

0 个答案:

没有答案