- Aar - op 20/10/2013 11:27:34
Laat je relevante code eens zien?
<?php
foreach($xml->$_GET['cat'] as $product) {
echo '<div class="product_box">';
echo '<h3>'.$product->name.'</h3>';
echo '<img src="'.$product->image.'" /><br />';
echo $product->description;
echo '<p class="product_price">'.$product->price.'</p>';
echo '<a href="shoppingcart.php?action=add&id='.$product->id.'" class="addtocart"></a>';
echo '<a href="product.php?cat='.$_GET['cat'].'&id='.$product->id.'" class="detail"></a>';
echo '</div>';
}
?>
Tot hier kwam ik met de productweergave (deze werkt)
en <?php
$xml = simplexml_load_file('../overig/producten/products.xml');
require_once('include/global.inc.php');
// Include functions
require_once('include/functions.php');
// Start the session
session_start();
// Process actions
foreach($xml->$_GET['id'] as $price) {
$cart = $_SESSION['cart'];
$action = $_GET['action'];
$id = $_GET['id'];
switch ($action) {
case 'add':
if ($cart) {
$cart .= ','.$id;
} else {
$cart = $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;
?> en deze geeft aan dat hij $cart niet herkent.. en dan zijn er nog de functies:
<?php
//error_reporting(0);
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p>U heeft geen artikelen in uw winkelwagen</p>';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$en = (count($items) > 1) ? 'en':'';
return '<p>U heeft <a href="shoppingcart.php">'.count($items).' artikel'.$en.' in uw winkelwagen</a></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="shoppingcart.php?action=update" method="post" id="cart">';
$output[] = '<table>';
foreach ($contents as $id=>$qty) {
$sql = $xml->$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="shoppingcart.php?action=delete&id='.$id.'" class="r">Verwijder</a></td>';
$output[] = '<td>'.$title.' - '.$description.'</td>';
$output[] = '<td>€'.$price.'</td>';
$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
$output[] = '<td>€'.($price * $qty).'</td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<p>Totaal: <strong>€'.$total.'</strong></p>';
$output[] = '<div><button type="submit">Update winkelwagen</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>Uw winkelwagen is leeg</p>';
}
return join('',$output);
}
?>
maar het werkt niet, de connectie is :
<?php
//error_reporting(0);
$url = '../Overig/producten/products.xml';
$temp = file_get_contents($url);
$db = simplexml_load_string($temp);
?>