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']);
$count开发者_开发问答ries[]=$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?
Try this:
<?php echo $country->getCountryName(); ?>
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.
精彩评论