php - Retrieve data from database in CakePHP -


i have database 2 tables: users , mails.

in mailscontroller.php controller have function history():

 public function history() {  $mails = $this->mail->find('id');  $this->set('mails', $mails);  $result = $this->mail->find('fromusername');  foreach($result $row){     $this->set('mails', $row);  }  } 

my goal print on page $mails sent username. in case this, not know code should put in history.ctp page.

can please me bit?

fromuserame in column save usernames in 'mails' table of database.

in mailscontroller.php:history() sent variable $mails view (history.ctp).

in view, can access $mails other php variable. since array, want use loop display data:

foreach ($mails $mail) {     echo $mail['mail']['fromusername']; // modify according data , required output. } 

to see $mails contains in script (for debugging purposes), can dump contents:

var_dump($mails); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -