0

How can I dialplay values of array of objects which is stored into session.

I make like this

//fetch array of countries from db

$countries = array();
    while($row = mysql_fetch_array($result)){

        $country = new Country();

        $country->setCountryName($row['country_name']);
        $country->setCountryNo($row['country_no']);
        $country->setCountryZipCode($row['country_zipcode']);

        $countries[]=$country;
    }

$_SESSION['countries']=$countries;

then display the values of the session like this

<select name="countries" id="countries">
        <?php foreach ($_SESSION['countries'] as $i=>$country ){?>
        <option><?php echo $_SESSION['countries'][$i]=>$country.getCountryName()?></option>   //here's the error
        <?php
        }
    ?>
    </select>

The error occurs when I display the values of session, any help plz?

1
  • Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ',' or ';' in C:\AppServ\www\crm\subpages\SearchCustomer.sub.php on line 14 . line 14 is where I print session values Commented Aug 8, 2011 at 10:32

2 Answers 2

1

Try this:

<?php echo $country->getCountryName(); ?>
Sign up to request clarification or add additional context in comments.

3 Comments

This error occurs : main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;Country&quot; of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in C:\AppServ\www\crm\subpages\SearchCustomer.sub.php on line
I assume the two snippets you posted in your question are from two different scripts. In which file is the Country class defined? You need to include that file in the script that displays the <select> element.
I already include the country file which have the country class, I try to make echo 'hi'; it works and loop as the number of returned countries.
0

You cannot save objects within session. I'm sorry. But you can store those as array of properties and restore it each time the script starts.

2 Comments

Are you sure we can't save objects within session in php ??
You will need to use serialization: bytes.com/topic/php/answers/…

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.