Undefined property in Foreach

1

I'm logging into my system and once I login, the idea is that the menu is updated according to the type of user profile, for which I'm doing from the database and showing the menu through a Foreach . However within the Foreach, when comparing one of the rows with a number, that is to say, with an id I get this error message and similar ones:

Message: Undefined property: mysqli::$id_man  

So I assume you're not recognizing the value of the row, why is it happening, how could you correct it?

Model

public function mostrar_menu(){

$id_tip= $this->session->userdata('tipo');

$this->db->select('id_mc, id_tip, id_man');
$this->db->from('mantenedores_cuenta');
$this->db->where('id_tip',$id_tip);
$menu = $this->db->get();


$horarios ="";
$informes="";


foreach ($menu as $row) {

if ($row->id_man == 1 ) {

$horarios .='<li class="active"><a href="<?= base_url("index.php/C_Horarios"); ?>"><i class="fa fa-circle-o"></i>Administrar Horarios</a></li>';

} 

if ($row->id_man == 2 ) {

$horarios .='<li><a href="<?= base_url("index.php/C_Calendar"); ?>"><i class="fa fa-circle-o"></i>Agendar Citas</a></li>';

}

if ($row->id_man == 3 ) {

$horarios .='<li><a href="<?= base_url("index.php/C_Citas"); ?>"><i class="fa fa-circle-o"></i>Consultar Citas</a></li>';

}

if ($row->id_man == 4 ) {

$informes .='<li class="active"><a href="<?= base_url("index.php/C_Porcentaje"); ?>"><i class="fa fa-circle-o"></i>Porcentaje de Citas</a></li>';

  }


  } //Fin del Foreach

 $menu_barra=" 

    <ul class='sidebar-menu'>
    <li class='header'>MENU</li>
    <li class='active treeview'>
      <a href='#'>
        <i class='fa fa-fw fa-calendar'></i> <span>Horarios</span>
        <span class='pull-right-container'>
          <i class='fa fa-angle-left pull-right'></i>
        </span>
      </a>
      <ul class='treeview-menu'>
       '$horarios'
      </ul>
    </li>
      <li class='treeview'>
     <a href='#'>
      <span class='glyphicon glyphicon-stats'></span><span>Informes</span> <i class='fa fa-angle-left pull-right'></i>
      </a>
      <ul class='treeview-menu'>
        '$informes'
      </ul>
    </li>
    <li><a href='documentation/index.html'><i class='fa fa-book'></i> <span>Documentación</span></a></li>
    <li><a href='documentation/index.html'><i class='fa fa-fw fa-sign-out'></i><span>Salir</span></a></li>

  </ul> ";

  return ($menu_barra);

  }

Also try to show it in this way, but I was not allowed in an array or at least that's what the message said, example: $ row ["id_man"] == 3

    
asked by CristianOx21 27.10.2017 в 17:53
source

1 answer

0

What you need is to convert $menu into array before using it in foreach ($menu as $row) with result() , try the following and tell me:

$menu = $this->db->get();
...
foreach ($menu->result() as $row)
{
    echo $row->id_man;
}

Greetings.

    
answered by 03.11.2017 в 18:12