开发者

Display values of array of objects

开发者 https://www.devze.com 2023-03-26 21:13 出处:网络
How can I dialplayvalues of array of objects which is stored into session. I make like this //fetch array of countries from db

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

精彩评论

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