MySQL aktualisiert den vorherigen Datensatzeintrag, wenn neue Einträge eingegeben werdenPhp

PHP-Programmierer chatten hier
Anonymous
 MySQL aktualisiert den vorherigen Datensatzeintrag, wenn neue Einträge eingegeben werden

Post by Anonymous »

Ich verfolge MySQL-Tabellen

store_update_stock Table

Code: Select all

+-----------------+------------+-----------------+
| update_stock_id | old_row_id | transfer_status |
+-----------------+------------+-----------------+
|               1 |          0 | Approved        |
|               2 |          0 | Approved        |
|               3 |          1 | Issue           |
|               4 |          2 | Issue           |
+-----------------+------------+-----------------+
store_update_stock_details Tabelle

Code: Select all

+-------------------------+-----------------+------+-----+------------+
| update_stock_details_id | update_stock_id | item | qty | unit_price |
+-------------------------+-----------------+------+-----+------------+
|                       1 |               1 |  400 |   1 |      10.00 |
|                       2 |               2 |  400 |   2 |      10.00 |
|                       3 |               2 |  401 |   2 |      10.50 |
|                       4 |               2 |  402 |   4 |      11.00 |
|                       5 |               3 |  400 |   2 |      10.00 |
+-------------------------+-----------------+------+-----+------------+
Zwei Tabellen werden durch update_stock_id verbunden. Ich möchte den Transferstatus früherer Datensätze (in diesem Beispiel sind die Datensatznummern 1, 2) als „Verifiziert“ aktualisieren, wenn ich neue Datensätze (in diesem Beispiel sind die Datensatznummern 3, 4) der Tabelle „store_update_stock“ einfüge. Die Ausgabe sollte wie folgt aussehen:

Code: Select all

+-----------------+------------+-----------------+
| update_stock_id | old_row_id | transfer_status |
+-----------------+------------+-----------------+
|               1 |          0 | Verified        |
|               2 |          0 | Verified        |
|               3 |          1 | Issue           |
|               4 |          2 | Issue           |
+-----------------+------------+-----------------+
Mein Controller wie folgt:

Code: Select all

public function verifyItemReqFromHD($id=null)
{
if ($this->form_validation->run() == true) {

$count = count($this->input->post('item_id'));
$items = $this->input->post('item_id');
$qts = $this->input->post('qty');
$unit_price = $this->input->post('unit_price');
$usid = $this->input->post('update_stock_id');

$total = 0;

for ($x = 0; $x < $count; $x++) {
$details[$x]['update_stock_id'] = null;
$details[$x]['item'] = $items[$x];
$details[$x]['qty'] = (-1)*$qts[$x];
$details[$x]['unit_price'] = $unit_price[$x];

}

$stock = array(
'old_row_id' => $usid,
'transfer_status' => 'Issue'
);

if ($this->Item_model->addItemReqFromHD($stock, $details, $id)) {
$this->session->set_flashdata('message', 'Successfully Issued..!!');
redirect('item/approvedItemsToIssue');
}

} else {
$this->session->set_flashdata('error', validation_errors());
$this->render('item/viewItemtoIssued', $meta, $this->data);
}
}
Modell wie folgt:

Code: Select all

function addItemReqFromHD($data,$details,$id)
{
$this->db->trans_start();
if ($this->db->insert('store_update_stock', $data)) {
$id = $this->db->insert_id();
foreach ($details as $detail) {
$detail['update_stock_id'] = $id;
$this->db->insert('store_update_stock_details', $detail);
}
}
$this->db->update('store_update_stock', array('transfer_status' => 'Verified'), array($id => $array['update_stock_id']));

$this->db->trans_complete();
if ($this->db->trans_status() === true) {
return true;
}
return false;
}
Erhielt jedoch nicht die gewünschte Ausgabe. Kannst du nicht verstehen, was ich falsch mache? Kann mir jemand helfen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post