0

我有 3 个列,我将在我的数据库的一个表中插入它们。每个表格的名称如下:

<h3><?= $title; ?></h3><?php echo form_open("admin/artikel/buat/");?>
<table width="95%">
    <tr>
        <td><b>Pilih Referensi Jurnal</b></td>
        <td>
            <input type="hidden" name="IDJurnal" id="IDJurnal" value="<?php echo $IDJurnal; ?>" />
            <input type="text" name="volume" id="volume" value="<?php echo $volume; ?>" readonly="readonly"  class="sedang" />
        <?php echo anchor_popup('admin/artikel/popup', 'Referensi Jurnal', array('class' => 'button')); ?>
    </td>
</tr>
<tr>
    <td><b>Kategori</b></td>
    <td>
        <?php
            echo form_dropdown('IDKategori', $kategori) . "";
        ?>
        </td>
    </tr>
    <tr>
        <td width="125"><strong>Judul</strong></td>
        <td><input type="text" name="judul" class="panjang"></td>
    </tr>
    <tr>
        <td width="125"><strong>Pengarang</strong></td>
        <td>
            <input type="text" name="pengarang" class="panjang">
            <input type="text" name="pengarang" class="panjang">
            <input type="text" name="pengarang" class="panjang">
        </td>
    </tr>
    <tr>
        <td><b>Abstract</b></td>
        <td>
        <?php
            $data = array('name' => 'abstract');
            echo $this->ckeditor->editor($data['name']);
        ?>
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="submit" class="button" value="Simpan">
            <input type="button" class="button" value="Batal" onClick="javascript: history.go(-1)" />
        </td>
    </tr>
<?php
            echo form_close();
?>

我想将每个表单名称中的值插入到我的 sql 表中,如下所示:

CREATE TABLE `pengarang`(
`IDPengarang` INT(11)NOT NULL AUTO_INCREMENT,
`IDArtikel` INT(11)NOT NULL,
`nama_pengarang` VARCHAR(255)NOT NULL,
PRIMARY KEY(`IDPengarang`))ENGINE = INNODB DEFAULT CHARSET = utf8;

在我的模型中是这样的:

function addArtikel() {
    $now = date("Y-m-d H:i:s");
    $data = array(
        'IDJurnal' => $this->input->post('IDJurnal'),
        'IDKategori' => $this->input->post('IDKategori'),
        'judul' => $this->input->post('judul'),
        'abstract' => $this->input->post('abstract'),
        'created_time' => $now,
        'created_by' => $_SESSION['username']
    );
    // $data1 = array(
        // 'IDJurnal' => $this->input->post('IDJurnal'),
        // 'IDKategori' => $this->input->post('IDKategori'),
        // 'judul' => $this->input->post('judul'),
        // 'abstract' => $this->input->post('abstract'),
        // 'created_time' => $now,
        // 'created_by' => $_SESSION['username']
    // );
    // $data2 = array(
        // 'IDArtikel' => $this->input->post('IDArtikel'),
        // 'nama_pengarang' => $this->input->post('pengarang')
    // );

    $this->db->insert('artikel', $data);
    // $this->db->insert_batch('artikel', $data1);
    // $this->db->insert_batch('pengarang', $data1);
}

在我的控制器中

function buat() {
    if ($this->input->post('judul')) {
        $this->MArtikel->addArtikel();
        $this->session->set_flashdata('message', 'Artikel telah di buat !');
        redirect('admin/artikel/index', 'refresh');
    } else {
        // konfigurasi ckfinder dengan ckeditor
        $this->load->library('ckeditor');
        $this->load->library('ckfinder');
        $this->ckeditor->basePath = base_url() . 'asset/ckeditor/';
        $this->ckeditor->config['toolbar'] = 'Full';
        $this->ckeditor->config['language'] = 'en';
        $this->ckfinder->SetupCKEditor($this->ckeditor, '../../../asset/ckfinder/');

        $data['title'] = "Tambah Artikel";
        $data['main'] = 'admin/artikel/artikel_buat';
        $data['jurnal'] = $this->MJurnal->getJurnalDropDown();
        $data['kategori'] = $this->MKategori->getKategoriDropDown();
        $this->load->vars($data);
        $this->load->view('dashboard/template');
    }
}

我应该在我的控制器和模型中添加什么,这将使我的表中的结果看起来像这样

IDPengarang     IDArtikel       nama_pengarang
1               1               testing 1
2               1               testing 2
3               1               testing 3

谢谢之前

4

0 回答 0