1

为什么在尝试使用以下方法访问任何数组键时出现此错误?

$product_cat = '22';
$db = JFactory::getDbo();
$query = $db->getQuery( true );
$query->select( $db->quoteName( array( 'name', 'alias', 'parent' ) ) );
$query->from( $db->quoteName( '#__k2_categories' ) );
$query->where( $db->quoteName( 'parent' )." = " .$product_cat );
$db->setQuery( $query );
$row = $db->loadObjectList();
print_r($row);
foreach ($row as $value) {
    foreach($value as $result) {
        echo '<ul>';
        echo '<li><a href="#">' . $result['name'] . '</a></li>';
        echo '</ul>';
    }
}

正在返回以下数组:

Array (
[0] => stdClass Object ( [name] => Stimulation Chemicals [alias] =>stimulation-chemicals [parent] => 22 )
[1] => stdClass Object ( [name] => Cementing Chemicals [alias] => 固井化学品 [parent] => 22 )
[2] => stdClass Object ( [name] => Improvement Oil Recovery [别名] => Improvement-oil-recovery [parent] => 22 )
[3] => stdClass 对象 ( [name] => 钻井液添加剂 [别名] => 钻井液添加剂 [parent] => 22 )
[4] => stdClass 对象 ( [name] => 溶剂和表面活性剂 [别名] => 溶剂-and-surfactants [parent] => 22 )
[5] => stdClass Object ( [name] => Coil Tubing Chemicals [别名] => coil-tubing-chemicals [parent] => 22 )
[6] => stdClass 对象([名称] => 生产化学品 [别名] => 生产化学品 [父] => 22))

所以我不确定发生了什么,我只是试图访问'name,'alias'和'parent'并将它们吐出在一个回显的html字符串中的不同位置。有任何想法吗?

4

1 回答 1

2

尝试这个:

foreach ($row as $value) {
   echo '<ul>';
   echo '<li><a href="#">' . $value->name . '</a></li>';
   echo '<li><a href="#">' . $value->alias . '</a></li>';
   echo '<li><a href="#">' . $value->parent . '</a></li>';
   echo '</ul>';
}
于 2015-02-17T14:03:02.693 回答