php - Get data from database and show in view -


i have foreach in controller - method:

foreach ($unanswered_questions $un_questions) {     //get asker_id , asked_id details     $un_questions->asker = $this->get_user_details($un_questions->asker_id); // asker_id can 0 or user id  } 

in my_controller have function

public function get_user_details($user_id) {     $user = new stdclass();      switch ($user_id) {         //if anonimous         case 0:             $user->?????? = $this->lang->line('anonymous'); //result anonymous text             $user->profile_picture = 'assets/images/default50.jpg';             break;          default:             $user = $this->users->select_details_by_id($user_id); // $user->first_name, $user->last_name, $user->username database (columns)             $user->profile_picture = $this->images->get_profile_image($user_id);             break;     }      return $user;  } 

so how can set data display correctly in view?

i need anonymous shown without link , if not anonymous show username link.

also in view have elements available users , not anonymous. if question not clear please ask me more details.

i assume in default: case $user being set object containing column names database table. need make same in case 0: case.

so need this

public function get_user_details($user_id) {     $user = new stdclass();      switch ($user_id) {         //if anonimous         case 0:             $user = new stdclass();              // make sure ->name matches actual column name              // have been generated table              $user->name = $this->lang->line('anonymous');             // add other properties may required in view             // default data.             $user->profile_picture = 'assets/images/default50.jpg';              $user->view_type = 1;              break;          default:             $user = $this->users->select_details_by_id($user_id); // $user->first_name, $user->last_name, $user->username database             $user->profile_picture = $this->images->get_profile_image($user_id);             $user->view_type = 0;             break;     }      return $user;  } 

so showing right data in view simple case of testing new property $user->view_type in view.

// in controller $data['title'] = 'a title`; $data['user'] = $user; $this->load->view('myview', $data);   // myview <html> <head> <title><?php echo $title;?></title> </head> <body>  <?php    if ( $user->view_type = 0 ) :       // show line    else:        // show without line    emdif;  ?> </body> </html> 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -