I'm having problem with inserting data if is clicked some value, i'm getting value from checkboxes but i want to insert some data with that values, i'm only inserting all data or just one, but i want to insert if is clicked '0' , '3' insert only inputs for them
if (!empty($vrednost['vrednost'])) {
// Loop to store and display values of individual checked checkbox.
$vrednost_count = ($vrednost['vrednost']);
// dd($vrednost_count);
foreach ($vrednost['vrednost'] as $selected) {
if ($selected == 0 || $selected == 3 || $selected == 10 || $selected == 5) {
$magacin = [];
for ($i = 0; $i <= $kolicina0; $i++) $magacin[] = ['id' => '333' . $odBroja0++, 'vrednost' => 0, 'uneto_by' => $user->fullName, 'uneto_at' => $uneto_at, 'status' => 0];
for ($i = 0; $i <= $kolicina3; $i++) $magacin[] = ['id' => '22' . $odBroja3++, 'vrednost' => 3, 'uneto_by' => $user->fullName, 'uneto_at' => $uneto_at, 'status' => 0];
for ($i = 0; $i <= $kolicina5; $i++) $magacin[] = ['id' => '555' . $odBroja5++, 'vrednost' => 5, 'uneto_by' => $user->fullName, 'uneto_at' => $uneto_at, 'status' => 0];
for ($i = 0; $i <= $kolicina10; $i++) $magacin[] = ['id' => '999' . $odBroja5++, 'vrednost' => 10, 'uneto_by' => $user->fullName, 'uneto_at' => $uneto_at, 'status' => 0];
} elseif($selected[]) { // what to write i try if select that or that
$magacin = [];
for ($i = 0; $i <= $kolicina0; $i++) $magacin[] = ['id' => '333' . $odBroja0++, 'vrednost' => 0, 'uneto_by' => $user->fullName, 'uneto_at' => $uneto_at, 'status' => 0];
for ($i = 0; $i <= $kolicina3; $i++) $magacin[] = ['id' => '22' . $odBroja3++, 'vrednost' => 3, 'uneto_by' => $user->fullName, 'uneto_at' => $uneto_at, 'status' => 0];
for ($i = 0; $i <= $kolicina5; $i++) $magacin[] = ['id' => '555' . $odBroja5++, 'vrednost' => 5, 'uneto_by' => $user->fullName, 'uneto_at' => $uneto_at, 'status' => 0];
}
}
}
This is my view, like u see in the botom you need to check what values('vrednost') you want to insert, if i click 0 and 3 i want only that 2 to insert in data (https://i.stack.imgur.com/n68g9.png)
In this example i check only 0, 5 and this is inserting all
array:4 [▼
0 => array:5 [▼
"id" => "3332"
"vrednost" => 0
"uneto_by" => "Petar Arsic"
"uneto_at" => "2020-12-11 10:31"
"status" => 0
]
1 => array:5 [▶]
2 => array:5 [▶]
3 => array:5 [▼
"id" => "9994"
"vrednost" => 10
"uneto_by" => "Petar Arsic"
"uneto_at" => "2020-12-11 10:31"
"status" => 0
]
]
array:2 [▼
0 => "0"
1 => "5"
]
https://i.stack.imgur.com/GAlrE.png
This is my controller, i need some if statement if to insert if clicked 1 or clicked all, or 3.
I tried to write a huge if else i got that values but its not accurate https://i.stack.imgur.com/yNQrE.png
PS. if value from checkbox('vrednost') he is making a one array with value of that checked checkbox
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire