Search code examples
cakephpcakephp-2.0cakephp-2.3cakephp-2.1

Undefined index: usertypename in cakephp


Controller part code

$Viewcustomer=$this->Viewcustomer->query("SELECT GROUP_CONCAT(usertype_name SEPARATOR ',') as usertypename, customer_name FROM `pre`.`customer` AS `Viewcustomer` WHERE `Viewcustomer`.`customer_status` = 0 AND `Viewcustomer`.`customer_type` = 'B1'  
GROUP BY `customer_id`  DESC"); 
$this->set("Viewcustomer",$Viewcustomer);

view part code

 foreach($Viewcustomer as $customers){
  echo  $customers['Viewcustomer']['usertypename'];
    }

Solution

  • usertypename should not come in $customers['Viewcustomer']['usertypename'];
    this should be
    $customers['0']['usertypename'];
    please print your array and share your code