Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:05:02+00:00 2026-05-28T18:05:02+00:00

I´m looking for some help about my shopping cart. I use a simple script.

  • 0

I´m looking for some help about my shopping cart. I use a simple script. Everything works as I want, but I don´t know how to find out if some products already exist, if they do I want to increment the value. The script is below:

for ($x=0;$x<count( $_SESSION["sess_name"]);$x++) {
    $x_id= $_SESSION["sess_id"];
    $x_name_prd= $_SESSION["sess_name_prd"];
    $x_number_prd= $_SESSION["sess_number_prd"];

   //if there is a product that is already in the cart then go to function check_me(); to do something to make the sess_number_prd +1 everytimes people click on the button.
    if ( $x_name_prd[$x]==$name_prd){
        check_me($x_name_prd[$x]);
    }
}

I have tried this method, but does not work

function check_me ($name_prd)  {
    for ($i=0;$i<count($_SESSION['sess_name']);$i++) {
        if (!in_array($_SESSION['sess_id'][$i],$)) {
            $temp_id[]=$_SESSION['sess_id'][$i];
            $temp_name[]=$_SESSION['sess_name_prd'][$i];

            $temp_num[]=+1;
        }
    }
    $_SESSION['sess_id']=$temp_id;
    $_SESSION['number_prd']=+1;
    $_SESSION['sess_name']=$temp_name;
} 

Can someone help me please..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:05:04+00:00Added an answer on May 28, 2026 at 6:05 pm

    If you’ve some control over the structure of the array stored in $_SESSION for your basket I’d recommend using something like this.

    /*Entry point
      It is assumed at this point you have the value product id ($pid) and initiated 
      your $_SEESION[<basket array index>] set - "basket" in this example
    */
    (isset($_SESSION['basket'][$pid]))? $_SESSSION['basket'][$pid]++ : $_SESSION['basket'][$pid] = 1;
    

    This approach doesn’t require the iterative comparison of each item in the basket to determine if an instance of it has already been added to the basket. This will allow for a simple

    foreach($_SESSION['basket'] as $product_id => $noOfProduct){
         /*Do your checkout thing here*/
    }
    

    to process the basket once you’re finished adding to it.

    Code posted in the comments by Alex, example of the problem not a solution

    for ($x=0;$x<count( $_SESSION["sess_id"]);$x++){
        $x_id= $_SESSION["sess_id"][$x];    //[$x] appended, presumed missing
        $x_id_prd= $_SESSION["sess_id_prd"];
        $x_name_prd= $_SESSION["sess_name"]; 
        $x_size_prd= $_SESSION["sess_size"]; 
        $x_color_prd= $_SESSION["sess_color"];
        $x_clr_code_prd= $_SESSION["sess_clr_code"]; 
        $x_num_prd= $_SESSION["sess_num"]; 
        if($x_id_prd[$x]==$id_prd 
          && $x_size_prd[$x]==$size_prd 
          && $x_color_prd[$x]==$color_prd 
          && $x_clr_code_prd[$x]==$clr_code ){ 
            //do something to get $_SESSION["sess_num"]+1;
        } 
    }
    

    End of comment code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for some help on a problem that I vaguely inquired about before,
I am a Ruby beginner and I'm looking for some help about Devise. My
I am looking for some statistics about .net developers which works with vs 2008
Looking for some help with a Labview data collection program. If I could collect
Looking for some help! I need to split a string at the last occurrence
looking for some help with images referenced within the stylesheet. I have no problems
Hi I'm looking for some help in mapping the following tables to a hibernate
I'm looking for some help on my discussion. We're discussing two solutions to a
I'm looking for some help with a dependency issue. In a nutshell, I've included
HI, I am new to the scrum methodology and looking for some help to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.