Jump to content

array as session variable on click to some image


jasmeet

Recommended Posts

when i click on image1 with id=1, it stores in session and when i click on image2 with id=2, it stores in session too next to the first one, and when i click on image3 with id=3, it stores in session next to id=2. and so on....

 

i hope you understand what i am asking ....

need help.

i know how to get value from array....

like

<?php// begin the sessionsession_start(); // create an array$my_array=array('cat', 'dog', 'mouse', 'bird', 'crocodile', 'wombat', 'koala', 'kangaroo'); // put the array in a session variable$_SESSION['animals']=$my_array; // a little message to say we have done itecho 'Putting array into a session variable';// loop through the session array with foreachforeach($_SESSION['animals'] as $key=>$value)    {    // and print out the values    echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';    }?>

/*************************************************************************************************************************************/

 

but wat i want is, cat ,dog,mouse,bird,crocodile,wombat,koala,kangaroo ... stored in array when i click on them....

 

i hope you understand..

 

please help!!!

 

thanks and regards,

jazz.. :)

<?phpsession_start(); $animals = array('cat', 'dog', 'mouse', 'bird', 'crocodile', 'wombat', 'koala', 'kangaroo'); if(isset($_GET['add_animal'])){$_SESSION['animals'][$animals[$_GET['add_animal']]] = 1;} echo '<h1>Animals to choose from</h1>'; foreach($animals as $key=> $value){// and print out the valuesecho "<a href='test2.php?add_animal={$key}'>{$value}</a></br>";} echo '<br/><br/>'; $added_animals = '';foreach($_SESSION['animals'] as $animal => $value){$added_animals .= $animal. ',';} echo 'The animal you have added are: ' . $added_animals; 

 
Try that.  Obviously change test2.php t your file name before you try it.

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.