| Autor | Zpráva | ||
|---|---|---|---|
| Spidee Profil |
Zdravim mam menší problém potřeboval bych dodělat do košíku přidávání množství a nevím jak na to. Přidávám sem scripty kdyby nekdo byl hodnej a poradil mi. Děkuji
cart.php <?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
// Start the session
session_start();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
break;
case 'delete':
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
break;
case 'update':
if ($cart) {
$newcart = '';
foreach ($_POST as $key=>$value) {
if (stristr($key,'qty')) {
$id = str_replace('qty','',$key);
$items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($id != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
for ($i=1;$i<=$value;$i++) {
if ($newcart != '') {
$newcart .= ','.$id;
} else {
$newcart = $id;
}
}
}
}
}
$cart = $newcart;
break;
}
$_SESSION['cart'] = $cart;
?>
<div id="shoppingcart">
<h1>Váš nákupní košík</h1>
<br>
<?php
echo writeShoppingCart();
?>
</div>
<br>
<div id="contents">
<h1>Prosím zkontrolujte množství...</h1>
<br>
<?php
echo showCart();
?>
<br>
<p><a href="obchod.php">Zpět do obchodu...</a></p>
</div>obchod.php <?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
// Start the session
session_start();
?>
<div id="shoppingcart">
<h1>Váš nákupní košík</h1>
<br>
<?php
echo writeShoppingCart();
?>
</div>
<br>
<div id="booklist">
<h1>Naše nabídka v obchodě</h1>
<br> <br>
<table width="800">
<tr>
<td>
<?php
date_default_timezone_set('Europe/Prague');
mysql_query("SET character_set_client=latin2");
mysql_query("SET collation_connection=latin2_czech_cs");
mysql_query("SET character_set_connection=latin2");
mysql_query("SET character_set_results=latin2");
$sql = 'SELECT * FROM zbozi ORDER BY ID';
$result = $db->query($sql);
while ($row = $result->fetch()) {
$output[] = '
<table width="800">
<tr>
<td height="25" width="800" colspan="2"><center><b>'.$row['nazev'].'</b></center></td>
</tr>
<tr>
<td height="125" width="200" align="center"><img src="../zbozi/'.$row['obrazek'].'.jpg"></td>
<td height="125" width="600">'.$row['popis'].'</td>
</tr>
<tr>
<td height="90" width="200" align="center">
<b>Skladem:</b> '.$row['skladem'].'
<br>
<b>Cena za kus:</b> '.$row['cena'].' Kč
<br>
</td>
<td height="90" width="600">
<center>
<FORM NAME=order>
<input type=hidden name="PRICE" value="'.$row['cena'].'">
<input type=hidden name="NAME" value="'.$row['nazev'].'">
<input type=hidden name="ID_NUM" value="'.$row['ID'].'">
<input type="text" size="2" maxlength="3" name="qty" value="1">
<a href="cart.php?action=add&id='.$row['ID'].'"><img src="images/plus.jpg"> Přidat do košíku</a>
<br> <br>
<a href="cart.php"><img src="images/cart.jpg"> Prohlídnout košík</a>
</FORM>
</center>
</td>
</tr>
</table>
<br>
<img src="images/untuch.jpg">
<br>
';
}
echo join('',$output);
?>
</td>
</tr>
</table>
</div> functions.inc.php <?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p>Nemáte žádné zboží v košíku. <img src="images/cart.jpg"></p>';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 'i':'';
return '<p>Máte <a href="cart.php">'.count($items).' věc'.$s.' v košíku.</a> <img src="images/cart.jpg"></p>';
}
}
function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
$output[] = '<table><tr><td width="80" align="center"><b>Odebrat</b></td><td width="400"><b>Položka</b></td><td width="80"><b>Cena za kus</b></td><td width="80"><b>Množství</b></td><td width="80"><b>Cena celkem</b></td></tr>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM zbozi WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td align="center"><a href="cart.php?action=delete&id='.$id.'" class="r"><img src="images/delete.jpg"></a></td>';
$output[] = '<td>'.$nazev.'</td>';
$output[] = '<td>'.$cena.' Kč</td>';
$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td>'.($cena * $qty).' Kč</td>';
$total += $cena * $qty;
$output[] = '</tr>';
}
$output[] = '</table><br>';
$output[] = '<p><b>Celkový součet:</b> <strong>'.$cena.' Kč</strong></p><br>';
$output[] = '<div><button type="submit">Aktualizovat košík</button><button type="submit">Objednat</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>Váš košík je prázdný.</p>';
}
return join('',$output);
}
?> |
||
| _es Profil |
Spidee:
Pravidla diskuse JPW a doporučení » 9. Nežádejte příliš. Hotová řešení příliš specifických či nadměrně složitých dotazů zde nedostanete. Okrem toho, ak by sa tým aj niekto chcel zaoberať, čo si má ako s tými tromi kódmi počať? Čo majú robiť, čo je v databáze, atď. Ak máš nejaký problém s nejakou zakúpenou aplikáciou, či ju potrebuješ o niečo rozšíriť, kontaktuj dodávateľa, alebo založ dotaz v sekcii „Práce a zakázky“. |
||
|
Časová prodleva: 14 let
|
|||
0