【发布时间】:2017-04-29 05:47:08
【问题描述】:
我需要一点 Codeigniter/php/Mysql 帮助,我有 3 个 mysql 表、项目、批处理和事务。在交易中,我有一列 transaction_type,在我的代码中我有 4 个单选按钮:传入、传出、损坏和过期。 我在事务、批次和项目表中也有一个列数量,如果有人选择了单选按钮传入,我想插入到事务表中,然后通过添加到两个表项目和批次中的列数量来更新字段数量中的值.如果选择了单选按钮 Outgoing 或 Damaged 或 Expired,则字段数量的值通过减去两个表项和批次中的列数量来更新。
这是我的插入脚本
if ($this->session->userdata('admin_login') != 1)
redirect('login', 'refresh');
if ($param1 == 'create') {
$data['transaction_date'] = $this->input->post('transaction_date');
$data['item'] = $this->input->post('item');
$data['batch'] = $this->input->post('batch');
$data['section'] = $this->input->post('section');
$data['transaction_type'] = $this->input->post('transaction_type');
$data['quantity'] = $this->input->post('quantity');
$this->db->insert('transactions', $data);
if($transaction_type == Incoming) {
$prepared = $this->prepare("UPDATE items SET balance = quantity+$balance WHERE id=?");
$this->execute($prepared, '');
}elseif($transaction_type == Outgoing){
$prepared = $this->prepare("UPDATE items SET balance = quantity-$balance WHERE id=?");
$this->execute($prepared, '');
}
$this->session->set_flashdata('flash_message' , get_phrase('items_issued_successfully'));
这是我的桌子
CREATE TABLE `batches` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`item` int(10) unsigned DEFAULT NULL,
`supplier` int(10) unsigned DEFAULT NULL,
`batch_no` varchar(40) DEFAULT NULL,
`manufacturing_date` date DEFAULT NULL,
`expiry_date` date DEFAULT NULL,
`balance` decimal(10,2) DEFAULT '0.00',
PRIMARY KEY (`id`),
KEY `item` (`item`),
KEY `supplier` (`supplier`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
CREATE TABLE `items` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`category` int(10) unsigned DEFAULT NULL,
`item` varchar(40) DEFAULT NULL,
`code` varchar(40) DEFAULT NULL,
`balance` decimal(10,2) DEFAULT '0.00',
`reorder_level` varchar(1000) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `category` (`category`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8
CREATE TABLE `transactions` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`transaction_date` varchar(255) DEFAULT NULL,
`item` int(10) unsigned DEFAULT NULL,
`batch` int(10) unsigned DEFAULT NULL,
`section` int(10) unsigned DEFAULT NULL,
`transaction_type` varchar(40) NOT NULL,
`quantity` decimal(10,2) DEFAULT '1.00',
PRIMARY KEY (`id`),
KEY `item` (`item`),
KEY `batch` (`batch`),
KEY `section` (`section`)
) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8
【问题讨论】:
-
你遇到了什么问题?
-
就像我的想法是,当我对事务视图运行插入时,插入运行良好,但它不会更新表 ITEMS 和 BATCH 的数量列
-
这是我的桌子
标签: php mysql codeigniter