Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to show all data from $result in my table but there's some error.
The notice is "Array to string conversion"
Here's the controller :

public function actionIndex()
  {
      $command = Yii::app()->db->createCommand('
        Select username as user
        From application_admin aa, application a
        Where a.app_id = aa.app_id');
        $reader = $command->query();
        $dataUser = $reader->readAll();

    $dataProvider = Application::model()->findAll();

    foreach ($dataProvider as $data) {
      $temp = array();
              $name = $data->name;
              $customer = $dataUser;
              $category = $data->appCategory->name;

              $temp['name'] = $name;
              $temp['customer'] = $customer;
              $temp['category'] = $category;
              $result[] = $temp;
    }

    $this->render('index',array('result'=>$result));
  }  

and this is the View :

<?php
    $i=1;
        foreach ($result as $data){
  ?>
        <tr class="center clickableRow">
            <div>
                <td><?php echo $i; ?></td>
                <td><?php echo $data['name']; ?></td>
                <td><?php echo $data['customer'];?></td>   //error in this line
                <td><?php echo $data['category'];?></td>
            </div>
        </tr >

        <?php
            $i++;
        }

  ?>   

Please give me some advice, thanks

share|improve this question
    
var_dump($data['customer']) and check the contents –  kevinabelita 20 hours ago
    
$customer = $dataUser[$j]; may be $dataUser[$j] is an array..! What is it..? –  Sudhir 20 hours ago
    
sorry it's my fault. i do some try and forget to undo, i use $j because i think $dataUser = $reader->readAll(); will return array –  Ken 20 hours ago
    
Change <?php echo $data['customer'];?> to <?php print_r($data['customer']);?> –  asprin 20 hours ago
    
@asprin it's show Array([user]=>'customer name') in every <td> –  Ken 20 hours ago
show 2 more comments

1 Answer

finally i get it

<td><?php echo $data['customer']['user'];?></td>

thanks all

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.