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 8628287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:29:55+00:00 2026-06-12T08:29:55+00:00

I want to display all session data but have some control over it. the

  • 0

I want to display all session data but have some control over it. the problem is, I can’t know exactly what’s stored in the session as it’s data from a shopping cart.

for example, here one variable in my session:

item_name_1 : Productname
item_quantity_1: 5

each products has some variables with a number. If there were 2 different products in the cart the second one would be

item_number_2 and so on.

there is also a variable called itemcount which tells how many different products are in the cart.

how can I tell php, that all variables that begin with item_name_ should be displayed for example in individual divs after all other variables, like total price?

this is what I use currently to print the session data:

<?php
foreach ($_SESSION as $key=>$val)
echo $key. ": ".$val. "<br>";
?>

this is what I see:

currency: EUR
shipping: 10
grandTotal: 70.5
itemCount: 4
item_name_1: Tomato Suppe
item_quantity_1: 1
item_price_1: 3.5
item_options_1:
item_name_2: Lentils Suppe
item_quantity_2: 14
item_price_2: 3.5
item_options_2:
item_name_3: Chicken Suppe
item_quantity_3: 1
item_price_3: 4.5
item_options_3:
item_name_4: Green Leaves Suppe
item_quantity_4: 1
item_price_4: 3.5
item_options_4:

Obviously I want to make it easier to read.

I can use echo $_SESSION[‘shipping’] for shipping cost to put it wherever I want, but how do I address the products?

say I want every product to be displayed within div and /div for example?

sorry for noob question.

thank you

  • 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-06-12T08:29:57+00:00Added an answer on June 12, 2026 at 8:29 am

    If you can not control the way the data is saved to the session you could write a simple helper function which retrieves the product data in a more usable format.

    function getSessionProducts()
    {
      $itemCount = $_SESSION['itemCount'];
      $products = array(); 
      for($i = 1; $i <= $itemCount; $i++) {
         $products[] = array(
           'name' => $_SESSION['item_name_'.$i],
           'quantity' => $_SESSION['item_quantity_'.$i],
           'price' => $_SESSION['item_price_'.$i],
           'options' => $_SESSION['item_options_'.$i]
        );
      }
      return $products;
    }
    

    You should of course add proper validation to check if the data in the $_SESSION array is set before accessing it.

    Use it as follows

    $products = getSessionProducts(); 
    foreach($products as $product) { 
        echo $product['name']; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display JQGrid with all column headers but without any data rows
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I have a an array of observable collections and I want to display all
I have a following code , I want to display all the attributes of
I have a little problem with my if(isset($_POST['submit'])) code. What I want is some
i want to display session time out message on my LogOn page. i have
i want to display all posts in Post table with say id=5 ...... controller
I want to display all the possible enum values as Radio buttons. I am
I want to display all records from table of current autorized user in my
I'm working on Ubuntu.(Linux) I want to display all .php pages to .html in

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.