Jump to content

ievernova

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Posts posted by ievernova

  1. im already using a foreach loop to output the cart items and have tried using soemthing like that already, as far as i understand i want to put teh foreach loop you mentioned above where the current foreach loop mis that display the cart items, how do i combine two foreach loops?

  2. Hi,

    I m trying to export a cart script to paypal as a form, for paypal to understand that ive sent multiple items i need to give each product in the array a number starting from one going up in numberical order,

    iv tried to use a for loop with an increment counthing variable for($counter=1;$counter>0;$coutner++) but cant get it to work with this existing code; whats the easiest way to do this?! i know how to get all of the variables and stuff into the form o i would just like to know how to output the array key number (is i?) as a variable where it says in teh code below...

     

    i want the final output to be something like this

                           

    1 ProductA Quantity: 20

    2 ProductB Quantity: 15

    3 ProductC Quantity: 6

     

    this is the point at which i output the cart before proceeding to the checkout,

     

    function writeShoppingCart() {
    $cart = $_SESSION['cart'];
    if (!$cart) {
    	return '<p>You have no items in your shopping cart</p>';
    } else {
    	// Parse the cart session variable
    	$items = explode(',',$cart);
    	$s = (count($items) > 1) ? 's':'';
    	return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</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="cart.php?action=update" method="post" id="cart">';
    	$output[] = '<table>';
    	foreach ($contents as $id=>$qty) {
    		$sql = 'SELECT * FROM syn_vinyl_product WHERE prod_id = '.$id;
    		$result = $db->query($sql);
    		$row = $result->fetch();
    		extract($row);
    		$output[] = '<tr>';
    		$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
    		$output[] = '<td>'.$prod_title.' by '.$artist.'</td>';
    		$output[] = '<td>£'.$price.'</td>';
    		$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
    		$output[] = '<td>£'.($price * $qty).' ////////////////ITEM NUMBER HERE /////////////////</td>';
    		$total = '';
    		$total += $price * $qty;
    		$output[] = '</tr>';
    	}
    	$output[] = '</table>';
    	$output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>';
    	$output[] = '<div><button type="submit">Update cart</button></div>';
    	$output[] = '</form>';
    } else {
    	$output[] = '<p>You shopping cart is empty.</p>';
    }
    return join('',$output);
    }

     

    the cart code

     

    <?php
    ##########
    ### saved from http://v3.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart
    ##########
    
    
    // Include MySQL class
    require_once('mysql.class.php');
    // Include database connection
    require_once('global.inc.php');
    // Include functions
    require_once('functions.inc.php');
    // Start the session
    session_start();
    // Process actions
    $cart = $_SESSION['cart'];
    $action ='';
    if (isset($_GET['action']))
    {
    $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;
    ?>

     

    THANKS ALOTT!!!!!!!!!

  3. the cart code

     

    <?php
    ##########
    ### saved from http://v3.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart
    ##########
    
    
    // Include MySQL class
    require_once('mysql.class.php');
    // Include database connection
    require_once('global.inc.php');
    // Include functions
    require_once('functions.inc.php');
    // Start the session
    session_start();
    // Process actions
    $cart = $_SESSION['cart'];
    $action ='';
    if (isset($_GET['action']))
    {
    $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;
    ?>

  4. Hi,

    I m trying to export a cart script into paypal, for paypal to understand that ive sent multiple items i need to give each product in the array a number starting from one going up in numberical order,

    iv tried to use a for loop with an increment counthing variable for($counter=1;$counter>0;$coutner++) but cant get it to work with this existing code; whats the easiest way to do this?! i know how to get all of the variables and stuff into the form i need to send to paypal so i would just like to know how to output the number from a variable where it says in teh code below...

     

    i want the final output to be something like this

                           

    1 ProductA Quantity: 20

    2 ProductB Quantity: 15

    3 ProductC Quantity: 6

     

    this is the point at which i output the cart before proceeding to the checkout,

     

    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>';
            
            foreach ($contents as $id=>$qty) 
                {
                $sql = 'SELECT * FROM syn_vinyl_product WHERE prod_id = '.$id;
                $result = $db->query($sql);
                $row = $result->fetch();
                extract($row);
                
                $output[] = '<tr>';
                $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
                $output[] = '<td>'.$prod_title.' by '.$prod_desc.'</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>';
                $output[] = '<td>//////////    OUTPUTT THE NUMBER HERE  /////////////</td>';
                
                $total = '';
                $total += $price * $qty;
                
                $output[] = '</tr>';
                }
                
            $output[] = '</table>';
            $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>';
            $output[] = '<div><button type="submit">Update cart</button></div>';
            $output[] = '</form>';
        }  

     

    THANKS ALOT!!!

  5. Hi,

     

    Is it possible to show the absolute UL of the image files uploaded after running this upload script? if so how?

    eg:

     

    http://mysite.com/admin/image1name.jpg

    http://mysite.com/admin/image2name.jpg

    http://mysite.com/admin/image3name.jpg

     

     

    ../admin/form.php:

     

    <form enctype="multipart/form-data" action="upload.php" method="post">
    Image1: <input name="userfile[]" type="file" /><br />
    Image2: <input name="userfile[]" type="file" /><br />
    Image3: <input name="userfile[]" type="file" /><br />
    Image4: <input name="userfile[]" type="file" /><br />
    <input type="submit" value="Upload" />
    </form>

     

    ../admin/Upload .php:

     

    <?php
    $success = 0;
    $fail = 0;
    $uploaddir = '';
    for ($i=0;$i<4;$i++)
    {
    if($_FILES['userfile']['name'][$i])
    {
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name'][$i]);
    $ext = strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
    if (preg_match("/(jpg|gif|png|bmp)/",$ext))
    {
    if (move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile)) 
    {
    $success++;
    } 
    else 
    {
    echo "Error Uploading the file. Retry after sometime.\n";
    $fail++;
    }
    }
    else
    {
    $fail++;
    }
    }
    }
    echo "<br> Number of files Uploaded:".$success;
    echo "<br> Number of files Failed:".$fail;
    
    ?>

     

    THANKS ALOT!!!!!!!!

×
×
  • 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.