0

Hello Stack Overflow i hope you are well today;

So i am using jQuery to append a form with more input fields; The Session is storing the data as an Array for the key: Children.

I would like to know show the user the data in that array how would this be done?

jQuery that adds the input fields (some pages previous)

 $('.children-main-add').click(function(){
    var attrName = $(this).attr('name');
    var count = $(this).attr('count');
    $(this).attr('count', (parseInt(count)+1))
    var input = $('<input />');
    input.attr('type','text')
    input.attr('name',attrName+"["+count+"]" ) 
    $('.children-main').append($('<li />').append(input));
    $('#content li').removeClass('alt');
    $('#content li:odd').addClass('alt');
    $(this).val('Add Another Child');
})

The data from the session : Key: children / Value: Array

If i was not clear on something please let me know !

I thank you in advance for your help

4
  • i have tried the usual method <?php if(isset($_SESSION['children'])) { echo $_SESSION['children']; } ?> Commented Mar 17, 2011 at 11:55
  • 1
    use this print_r($_SESSION['children']); Can you show any example with data. Commented Mar 17, 2011 at 11:57
  • 1
    please use print_r for echoing arrays to the screen, and if it doesnt work use var_dump so we can better understand what the array holds Commented Mar 17, 2011 at 11:58
  • @Gaurav thanks that worked but how would i show it in an eligible format atm it displays like this: Array ( [0] => Julia Roberts [1] => Zaraki Akram [2] => Simon Evans Smith ) Commented Mar 17, 2011 at 12:00

1 Answer 1

2

if you want to show them as an continue string

use impode(',' , $_SESSION['children']);

Or

if(isset($_SESSION['children']) && is_array($_SESSION['children']))
{
    foreach($_SESSION['children'] as $child)
    {
      echo $child."<br />";  
      // some other html
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

i actually want to show them seperately i.e. Julia Roberts <br /> Zaraki Akram <br /> Simon Evans Smith So each on a new line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.