Jump to content

PHP Shop


jibber4568

Recommended Posts

HI have created a shopping cart through a number of examples using php and ajax.

This cart allows me to drag an item into the cart and then the cart updates displaying that items class name.

 

I have never done any php before so am having trouble adding to this.

 

I want to add to the script an if statement that would say for example

 

if(id="item1")

{

price=20

}

else

  if{(id="item2")

    {

    price=15

    }

 

etc etc

 

I hope you can understand what i mean.

 

Would be extremely gratefull if someone could help me with how to write this within my script.

 

html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="stylesheet/design.css" type="text/css">
    <script type="text/javascript" src="javascript/effect.js"></script>
    <script type="text/javascript" src="javascript/prototype.js"></script>
    <script type="text/javascript" src="javascript/src/scriptaculous.js?load=effects,dragdrop"></script>
    <link rel="stylesheet" href="StyleSheet.css" type="text/css" media="screen" />
    <script language="JavaScript" type="text/javascript" src="Javascript/JScript.js"></script>
    

</head>
<body>

    <div id="wrapper">
    
       <div id="bordertop"> 
       </div>
        <div id="bordermiddle"> 
        
            <div id="header" style=" position: relative; left: 3.5%; bottom: 20px; width: 96.5%; height: 200px;">
            </div>
        
          
             <div id="menu" style="position: relative; left: 3%; bottom: 20px; width: 96.5%">
            
           <a href ="http://www.google.com"><img src="images/images/home_btn.png" border="0" alt="Home"/></a><a href ="javascript:artists();"><img src="images/images/artists_btn.png" border="0" alt="Artists" /></a><a href ="http://www.google.com"><img src="images/images/shop_btn.png" border="0" alt="Shop" /></a><a href ="javascript:accordion();"><img src="images/images/events_btn.png" border="0" alt="Events" /></a><a href ="/mp3/mp3player.swf" onclick="loadSWF(this.href); return false;"><img src="images/images/listen_btn.png" border="0" alt="Listen" /></a><a href ="http://www.google.com"><img src="images/images/contact_btn.png" border="0" alt="Contact" /></a> 
            </div>
           
            <div id="content" style="position:relative; left:3%;">
           <div class="item" id="WaxhedsCd">
             <img  id="item1" src="images/img.jpg">
         </div>
          <div class="item" id="KoasteCd">
             <img src="images/koastecd.jpg">
         </div>
          <div class="item" id="OlliePCd">
             <img src="images/img.jpg">
         </div>
          <div class="item" id="WaxhedsTee">
             <img src="images/img.jpg">
         </div>
          <div class="item" id="WaxhedsBag">
             <img src="images/img.jpg">
         </div>
          <div class="item" id="KoasteTee">
             <img src="images/img.jpg">
         </div>
         <div class="item" id="PhilEBluntCd">
             <img src="images/img.jpg">
         </div> 
         <div class="item" id="OlliePTee">
             <img src="images/img.jpg">
         </div>    
   
<div class="cart">
        <img id="cart_img" src="images/cart.gif" style="float:left"> <label id="titles">Drag your items here...</label>
        <div id="split_line"></div>
        <div id="items" style="width:215;height:200">
            
        </div>
    </div>
               
               
            </div>
          </div>
        <div id="borderbottom"> 
        </div>
       
      
    </div>
   

</body>

  <script>
    makeDraggableItems();
  </script>
</html>

 

php

<?php
session_start();
$elements_arr;
$elementID = $_GET['id'];
if(isset($_SESSION['user_id']))
{
    $elements_arr = $_SESSION['user_id'];
    if(isset($elements_arr[$elementID]))
        {
            $no_of_items = $elements_arr[$elementID];
            $no_of_items = (int)$no_of_items + 1 ;
            $elements_arr[$elementID] = $no_of_items ;
        }
        else
            $elements_arr[$elementID] = 1;
    $_SESSION['user_id'] = $elements_arr;
}
else
{
    $elements_arr[$elementID] = 1;
    $_SESSION['user_id'] = $elements_arr;
}
$keys = array_keys($elements_arr);
for($i = 0 ; $i < count($keys) ; $i++)

{
    print("<div id='div'".$keys[$i].">");
    print(" <img src='images/img.jpg' style='margin-top:5px;' width=20px height= 20px> ");
    print("<label class='ajax_item'>".$keys[$i]."  (".$elements_arr[$keys[$i]].")</label> ");
    print(" <img src='images/DeleteIcon.gif' class='delete_img' onclick=(removeItem('".$keys[$i]."'));>");
    print("<br>");
    print("<div id='split_line'></div>");
    print("</div>");
}
?>  

 

If it helps you can also see this example at the following url

 

http://jibber4568.gigacities.net/index2.php

 

Many thanks

 

Jibber4568

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.