开发者

Display values of array of objects

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜