oto moj kontroler:
Funkcja dodajaca dane do cookie
function addCards($segment=1, $price='') { //echo 'value2 '.$value2.'- value1 '.$value1.'= value '.$value; redirect('koszyk/aktualna_cena'); }
funckja wyswietlajaca widok:
function order_product() { $widok['left'] = $this->get_category(); $widok['right'] = $this->get_bestseller(); //$widok['zakupy'] = $this->sum_all(); //$widok['licznik'] = $this->counter(); $widok['tytul'] = 'Twoj koszyk'; $pozycja = 0; $widok['center'] =' <table class="basket"> <tr> <th>Pozycja</th> <th style="text-align: center;">Nazwa</th> <th>Ilość</th><th>Cena brutto</th><th>Wartość</th> <th>Usuń</th> </tr>'; { foreach ($_COOKIE['cookie'] as $name => $value) { $pozycja++; $query = $this->Kategorie_model->get_books_by_ID($name); $widok['center'] .= $this->load->view('Ksiegarnia/order_product_view', array('data' => $query,'pozycja' =>$pozycja),True); } $widok['center'] .='</table>'; } $this->load->view('Ksiegarnia/index_logged',$widok); }
funnkcja obliczajaca cene:
function aktualna_cena() { $zakupy = 0; { foreach ($_COOKIE['cookie'] as $name => $value) { $query = $this->Kategorie_model->get_books_by_ID(mysql_real_escape_string(HTMLSpecialChars(addslashes($name)))); if($query->num_rows >0) { foreach($query->result() as $item) { $cena = $item->BOOK_Price; } $zakupy += $cena*$value; } } } redirect('koszyk/aktualna_ilosc'); }
i widok:
<?php foreach($data->result() as $item):?> <form action="<?=base_url()?>index.php/koszyk/zmien_ilosc/<?php $item->BOOK_ID;?>" method="POST"> <tr> <td><?=$pozycja?></td> <td><?=$item->BOOK_Title?></td> <td><input type = "text" class ="tekst" name="produkt_<?php $item->BOOK_ID;?>" value=""/></td> <td><input type="submit" class="sub" name="zmien" value = "Zmien"/> <input type="hidden" class="hid" name="zmien" value = "Zmien"/> </td> <td><?=number_format($item->BOOK_Price,2, '.', '')?>zł</td><td><?=anchor('koszyk/deleteCards/'.$item->BOOK_ID,'X');?></td> </tr> </form> <script type="tetext/javascript"> </script> <?php endforeach; ?>
Prosze o pomoc, bo dosc dlugo juz sie z tym mecze, i nie mam za bardzo pomyslu jak to rozwiazac....