Jump to content

Php Array value shuffle


jay_bo

Recommended Posts

This is my whole block of code.....

 

if (isset($_GET['id'], $_GET["delete"]) && is_numeric($_GET['id']) && $_GET['delete'] =="true")//This line gets the value and reads it

{

  $prod_id = (int) $_GET['id'];

  unset($_SESSION["product"][$prod_id]);

  shuffle($prod_id);

  header ('Location: products.php?cat=1');

}

 

Where am i going wrong?

Link to comment
Share on other sites

try

<?php
if (isset($_GET['id'], $_GET["delete"]) && is_numeric($_GET['id']) && $_GET['delete'] =="true")//This line gets the value and reads it
{
   $prod_id = (int) $_GET['id'];
   unset($_SESSION["product"][$prod_id]);
   $_SESSION["product"] = array_values($_SESSION["product"]);   
   header ('Location: products.php?cat=1');
}
?>

Link to comment
Share on other sites

Sorry i should of explained what i am trying to do....I am trying to remove an item from my shopping cart which seems to work, but when i readd items they seem to mess up.

 

For example;

 

Before deletion:

Quantity      Product                                    Price

Quantity: 2 - Microsoft Windows 7 Professional - £319.98 Remove

Quantity: 3 - Microsoft Windows Vista Ultimate - £269.97 Remove

 

 

After i remove them and readd products:

Quantity      Product                              Price

Quantity: 2 - Microsoft Windows 7 Professional - £319.98 Remove

Quantity: 2 - - £0  Remove

 

You see the second item i add has no title or price.

 

This is my cart php code

 

 
    $cost = number_format($_SESSION["cost"],2,".",","); //Stores data into the variable
    echo '<form name="cart" method="post" action="shopping-cart.php" >';
    echo '<p class="center"><strong>SHOPPING CART</strong></p>';
    echo '<p>No of Items: <strong>'.$_SESSION['products'].'</strong><br/>Total Price: <strong>£'.$_SESSION['cost'].'</strong></p>'; //Variables displays the data
    echo '<input type="hidden" name="price" value="'.$row["price"].'">';
    echo '<p class="button"><input type="submit" name="Submit" value="Check Out"></p>';
    echo '</form>';
    echo '<form name="cart" method="post" action="logout.php" >';
    echo '<p class="button"><input type="submit" name="Submit" value="Logout"></p>';
    echo '</form>';

 

This is My shopping cart deletion code

 
    if (isset($_GET['id'], $_GET["delete"]) && is_numeric($_GET['id']) && $_GET['delete'] =="true")//This line gets the value and reads it
{
   $prod_id = (int) $_GET['id'];
   unset($_SESSION["product"][$prod_id]);
   $_SESSION["product"] = array_values($_SESSION["product"]);   
   header ('Location: products.php?cat=1');
}

 

Many thanks guys for your help so far.

Link to comment
Share on other sites

Array ( [6] => Array ( [title] => Microsoft Windows 7 Professional [description] => Windows 7 Professional includes all the Home Premium features you love and the business features your work demands. Connect to company networks easily and more securely and share files across the various PCs in your home. [price] => 159.99 [qty] => 2 )

[7] => Array ( [title] => Microsoft Windows Vista Ultimate [description] => Windows 7 Professional includes all the Home Premium features you love and the business features your work demands. Connect to company networks easily and more securely and share files across the various PCs in your home. [price] => 89.99 [qty] => 3 )

[8] => Array ( [title] => Microsoft Windows Vista Home [description] => Windows 7 Professional includes all the Home Premium features you love and the business features your work demands. Connect to company networks easily and more securely and share files across the various PCs in your home. [price] => 69.99 [qty] => 0 )

[28] => Array ( [title] => Nero 8 [description] => fdfdsfds [price] => 2.99 [qty] => 0 ) )

 

Link to comment
Share on other sites

Array ( [6] => Array ( [title] => Microsoft Windows 7 Professional [description] => Windows 7 Professional includes all the Home Premium features you love and the business features your work demands. Connect to company networks easily and more securely and share files across the various PCs in your home. [price] => 159.99 [qty] => 2 )

 

Whatever sets the [6], be it product_id or whatever, thats what you want to unset

unset($array[6])//unset($array[$procuct_id])

 

 

HTH

Teamatomic

Link to comment
Share on other sites

Oh i forgot to remove that from something i was trying before..this is my code now which removes the products...

  $prod_id = (int) $_GET['id'];

  unset($_SESSION['product'][$prod_id]); 

  header ('Location: products.php?cat=1');

 

At the moment i have one item in my shopping cart which has a quantity of two...The item is bold below but ive noticed that there are other items there already which dont have a quantity, should they actually be there?

 

Array ( [6] => Array ( [title] => Microsoft Windows 7 Professional [description] => Windows 7 Professional includes all the Home Premium features you love and the business features your work demands. Connect to company networks easily and more securely and share files across the various PCs in your home. [price] => 159.99 [qty] => 2 )

 

[7] => Array ( [title] => Microsoft Windows Vista Ultimate [description] => Windows 7 Professional includes all the Home Premium features you love and the business features your work demands. Connect to company networks easily and more securely and share files across the various PCs in your home. [price] => 89.99 [qty] => 0 )

 

[8] => Array ( [title] => Microsoft Windows Vista Home [description] => Windows 7 Professional includes all the Home Premium features you love and the business features your work demands. Connect to company networks easily and more securely and share files across the various PCs in your home. [price] => 69.99 [qty] => 0 )

 

[28] => Array ( [title] => Nero 8 [description] => fdfdsfds [price] => 2.99 [qty] => 0 ) )

 

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.