Ja nu har jeg viklet den frem og tilbage nogle gange det forslag fra:
http://www.udvikleren.dk/PHP/Thread.aspx/6/29021/LastPage/Men kan ikke rigtig finde en løsning på hvordan jeg kan få gemt farvens navn og størrelsen inklusiv den beregnede pris i et array da mine drop down lister allerede bruger deres "value" til at gemme den pris stigning der kommer hvis du vælger den mulighed.
Håber der er nogen der kan give nogle gode forslag =).
Her kommer lidt koder i kan kikke på og se hvordan det fungerer.
Dette er den del der får produktet vist.
<div class="BlockContent-body">
<?php
$category = $_GET['c'];
$product = getProductDetail($pdId);
extract($product);
$_SESSION['price']=$pd_price;
?>
<table class="table" width="100%" border="0">
<td valign="top" width="50%">
<div>
<a href="<?php echo $pd_image; ?>" rel="lightbox[roadtrip]"><img src="<?php echo $pd_image; ?>" width="240px" alt="Produkt billed" border:0" /></a>
</div>
<div>
<h6>Flere billeder:</h6>
</div>
<div>
<?php
(str_word_count($pd_all_image, 1, '0123456789_;&'));
$counts = str_word_count($pd_all_image, 0, '0123456789_.;&');
$picShow = explode(",", $pd_all_image);
$e=$counts - "1";
$antal=1;
for ($i=0; $i<=$e; $i++)
{
if ($antal==3 OR $antal==6 OR $antal==9 OR $antal==12 OR $antal==15 OR $antal==18 OR $antal==21 OR $antal==24 OR $antal==27 OR $antal==30)
{
$antal++;
echo '<a href="images/produkter/' . $picShow[$i] . '" rel="lightbox[roadtrip]"><img src="images/produkter/' . $picShow[$i] . '" width="80px" alt="Produkt billed" border:0" /></a>';
echo '<br />';
}else{
$antal++;
echo '<a href="images/produkter/' . $picShow[$i] . '" rel="lightbox[roadtrip]"><img src="images/produkter/' . $picShow[$i] . '" width="80px" alt="Produkt billed" border:0" /></a>';
}
}
?>
</div>
</td>
<td valign="top" width="50%">
<div>
<h2 class="PostHeaderIcon-wrapper"><span class="PostHeader"><?php echo $pd_name; ?></span></h2>
<p><?php echo $pd_description; ?></p>
<br /><br />
<?php
$sizecounts = str_word_count($pd_size, 0, '-1234567890/;&');
$sizeShow = explode(",", $pd_size);
$d=0;
$e=$sizecounts-1;
$n=$pd_size_price_change;
echo '<label for="size">Vælg størrelse her: </label>';
if ($pd_price_varies==1)
{
echo '<select name="size">';
for ($i=0; $i<=$e; $i++)
{
echo '<option value="' . $sizeShow[$i] . '">' . $sizeShow[$i] . '</option>';
}
}
if ($pd_price_varies==2)
{
echo '<select name="size">';
for ($i=0; $i<=$e; $i++)
{
echo '<option value="' . $sizeShow[$i] . '">' . $sizeShow[$i] . '</option>';
}
}
if ($pd_price_varies==3)
{
echo '<select name="size" onchange="sizeChanged(this.value)">';
for ($i=0; $i<=$e; $i++)
{
if ($i==0 AND $d==0)
{
echo '<option selected="selected" value="' . $pd_price . '">' . $sizeShow[$i] . '</option>';
$d++;
}elseif ($i<$n){
echo '<option value="' . $pd_price . '">' . $sizeShow[$i] . '</option>';
$d++;
}else{
echo '<option value="' . $pd_price_size . '">' . $sizeShow[$i] . " + " . $pd_price_size . '</option>';
$d++;
}
}
}
if ($pd_price_varies==4)
{
echo '<select name="size" onchange="sizeChanged(this.value)">';
for ($i=0; $i<=$e; $i++)
{
if ($i==0 AND $d==0)
{
echo '<option selected="selected" value="' . $pd_price . '">' . $sizeShow[$i] . '</option>';
$d++;
}elseif ($i<$n){
echo '<option value="' . $pd_price . '">' . $sizeShow[$i] . '</option>';
$d++;
}else{
echo '<option value="' . $pd_price_size . '">' . $sizeShow[$i] . " + " . $pd_price_size . '</option>';
$d++;
}
}
}
echo '</select>';
echo '<br />';
echo '<br />';
$colorcounts = str_word_count($pd_color, 0, ';&');
$colorShow = explode(",", $pd_color);
$g=$colorcounts - "1";
$j=0;
$m=$pd_color_price_change;
echo '<label for="color">Vælg farve her: </label>';
if ($pd_price_varies==1)
{
echo '<select name="color">';
for ($t=0; $t<=$g; $t++)
{
echo '<option value="' . $colorShow[$t] . '">' . $colorShow[$t] . '</option>';
}
}
if ($pd_price_varies==2)
{
echo '<select name="color" onchange="colorChanged(this.value)">';
for ($t=0; $t<=$g; $t++)
{
if ($t==0 AND $d==0)
{
echo '<option selected="selected" value="' . $pd_price . '">' . $colorShow[$t] . '</option>';
$d++;
}elseif ($t<$m){
echo '<option value="' . $pd_price . '">' . $colorShow[$t] . '</option>';
$d++;
}else{
echo '<option value="' . $pd_price_color . '">' . $colorShow[$t] . " + " . $pd_price_color . '</option>';
$d++;
}
}
}
if ($pd_price_varies==3)
{
echo '<select name="color">';
for ($t=0; $t<=$g; $t++)
{
echo '<option value="' . $colorShow[$t] . '">' . $colorShow[$t] . '</option>';
}
}
if ($pd_price_varies==4)
{
echo '<select name="color" onchange="colorChanged(this.value)">';
for ($t=0; $t<=$g; $t++)
{
if ($t==0 AND $d==0)
{
echo '<option selected="selected" value="' . $pd_price . '">' . $colorShow[$t] . '</option>';
$d++;
}elseif ($t<$m){
echo '<option value="' . $pd_price . '">' . $colorShow[$t] . '</option>';
$d++;
}else{
echo '<option value="' . $pd_price_color . '">' . $colorShow[$t] . " + " . $pd_price_color . '</option>';
$d++;
}
}
}
echo '</select>';
?><br /><br /><br />
<h3><div id="priceDiv">Pris: <?php echo $pd_price; ?> kr.</div></h3>
<input name="btnContinue" type="submit" id="btnContinue" value="Køb" onClick="window.location.href='<?php echo $cart_url ?>';" />
</div>
Med disse ajax koder som jeg har i toppen af produkt siden,
<script type="text/javascript">
function sizeChanged(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser understøtter ikke HTTP Request. Du kan desværre ikke bruge vores design selv side uden at opdatere din browser.");
return;
}
var url="library/tekstil/sizeChange.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function colorChanged(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser understøtter ikke HTTP Request. Du kan desværre ikke bruge vores design selv side uden at opdatere din browser.");
return;
}
var url="library/tekstil/colorChange.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("priceDiv").innerHTML=xmlhttp.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// kode for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// kode for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
</script>
Henter jeg disse 2 sider ind.
sizeChanged.php
<?php
session_start();
$_SESSION['extraSize']=$_GET["q"];
if(isset($_SESSION['extraColor']))
{
if($_SESSION['extraColor']==$_SESSION['price'])
{
if ($_SESSION['extraSize']==$_SESSION['price'])
{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}else{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraSize'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}
}else{
if ($_SESSION['extraSize']==$_SESSION['price'])
{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraColor'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}else{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraSize']+$_SESSION['extraColor'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}
}
}else{
if ($_SESSION['extraSize']==$_SESSION['price'])
{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}else{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraSize'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}
}
?>
colorChanged.php
<?php
session_start();
$_SESSION['extraColor']=$_GET["q"];
if(isset($_SESSION['extraSize']))
{
if($_SESSION['extraSize']==$_SESSION['price'])
{
if ($_SESSION['extraColor']==$_SESSION['price'])
{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}else{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraColor'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}
}else{
if ($_SESSION['extraColor']==$_SESSION['price'])
{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraSize'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}else{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraColor']+$_SESSION['extraSize'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}
}
}else{
if ($_SESSION['extraColor']==$_SESSION['price'])
{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}else{
$_SESSION['priceCalculated']=0;
$_SESSION['priceCalculated']=$_SESSION['price']+$_SESSION['extraColor'];
echo 'Pris: ' . $_SESSION['priceCalculated'] . ' kr.';
}
}
?>
Som sagt så skal jeg have lavet så jeg får gemt en farve, en størrelse og en pris i et array alt efter hvad kunden vælger af størrelse og farve, og så skrive det ind i min database til senere brug.
Indlæg senest redigeret d. 09.07.2009 15:56 af Bruger #15117