Jump to content

Session Variables (Storing accumulated values?)


Solarpitch

Recommended Posts

Hey guys,

Bascially what I am trying to achieve is..

I want to set up a session variable that keeps track of values that are added to it across different pages in a site.

eg:

session variable = 'id_values'

Page1                            Page2

option1 (id=1)                  option1 (id=1)
option2 (id=2)                  option2 (id=1)
option3 (id=3)                  option3 (id=1)
option4 (id=4)                  option4 (id=1)

So if user select option1 and option4 on page 1, it stores the values 1 & 4 in 'id_values' . . then

if user select option1 and option2 on page 2, it stores the values 1 & 2 in 'id_values' along with page 1 values. so

'id_values' = {1, 4, 1, 2} . . hahaha I hope that makes sense!

Anyone here handy at using session variables?
yes... this could be very simply done using session variables... just use a different dimension of your session array.  in your example, on page 1, if it's clicked:

[code]if ($_POST['submit']) {
  if (is_array($_POST['options']) {
      foreach ($_POST['options'] as $array_element) {
          $_SESSION['checked_options'][] = $array_element);
      }
  }
}[/code]

With something like the above, you just have a 2 dimensional array where all of your clicked options are listed in the $_SESSION['checked_options'] array.
Let me give you a little piece of advice... PHP is a GOD among languages when it comes to array support.  Enjoy it while you can because if you try to go to another language (say, VBscript, KiX, etc), it's a nightmare.  =P

and if you have problems, you always have us.  =P

Archived

This topic is now archived and is closed to further replies.

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