agito
(The3cube)
1
hi all,
i’ve got problem on display string value from array value on CHtml::listdata
i want to keep data array on variable, but i try to display array with :
$models = user::model()->findAll(" sex='male' ");
$tripsArray = CHtml::listData($models, 'name', 'contact');
print_r($tripsArray);
foreach ($tripsArray as $tripsArray) {
echo $tripsArray."<br>";
}
and the result just display contact and name was not displayed.
how to display name and contact ?
thanks for advices
This how U wrote:
CHtml::listData($models, ‘name’, ‘contact’);
is generating ‘name’ as value and ‘contact’ like label, that’s why only ‘contact’ is displayed.
Please check :
CHtml::listData($models, ‘name’, ‘contact’);
http://www.yiiframework.com/doc/api/1.1/CHtml#listData-detail
Seems that I misunderstood U:
print_r($tripsArray);
foreach ($tripsArray as $tripsArray) {
echo $tripsArray."<br>";
}
if U want to display trough foreach:
print_r($tripsArray);
foreach ($tripsArray as $key => $tripArray) {
echo $key.$tripArray."<br>";
}
since ‘name’ is key and $tripArray is value
1 Like