-- -- Table structure 'charge _ logs' -- Create table if not exists 'charge _ logs '( 'Id' int (11) not null AUTO_INCREMENT, 'Charge _ id' int (11) not null, 'Title' text not null, Primary key ('id ') ) ENGINE = InnoDB default charset = utf8 AUTO_INCREMENT = 2; -- -- The data in the table is stored in 'charge _ logs' -- Insert into 'charge _ logs' ('id', 'charge _ id', 'title') VALUES (1, 1, 'xxxxxxx '); -- -- Table structure 'user _ charges' -- Create table if not exists 'user _ charges '( 'Id' int (10) unsigned not null AUTO_INCREMENT, 'User _ id' int (10) not null, 'Charge _ type' int (3) not null, 'Charge _ subtype' int (3) not null, 'Charge _ credits 'int (3) not null, 'Buy _ date' timestamp not null default '2017-00-00 00:00:00 ', 'Valid _ to' timestamp not null default '2017-00-00 00:00:00 ', 'Next _ charge_date 'timestamp not null default '2017-00-00 00:00:00 ', 'Payment' varchar (50) not null, Primary key ('id ') ) ENGINE = InnoDB default charset = utf8 AUTO_INCREMENT = 2; -- -- Store the data in the table 'user _ charges' -- Insert into 'user _ charges '('id', 'user _ id', 'charge _ type', 'charge _ subtype', 'charge _ credits ', 'Buy _ date', 'valid _ to', 'next _ charge_date ', 'payment') VALUES (1, 1, 1, 1,100, '2017-09-09 00:00:00 ', '2017-09-16 00:00:00', '2017-00-00 00:00:00 ', 'paypal '); Use select query in zend_db_table_abstract
$ Select = $ this-> getAdapter ()-> select (); $ Select-> from (array ('uc' => 'user _ charges ')) -> JoinLeft (array ('cl' => 'charge _ logs'), 'uc. id = cl. charge_id ', array ('title ')) -> Where ('uc. user_id =? ', $ Id ); Return $ this-> getAdapter ()-> fetchAll ($ select ); If Mapper is used, you can use $ Select = $ this-> getDbTable ()-> getAdapter ()-> select (); $ Select-> from (array ('uc' => 'user _ charges ')) -> JoinLeft (array ('cl' => 'charge _ logs'), 'uc. id = cl. charge_id ', array ('title ')) -> Where ('uc. user_id =? ', $ Id ); Return $ this-> getDbTable ()-> getAdapter ()-> fetchAll ($ select ); Output result Array (1 ){ [0] => array (10 ){ ["Id"] => string (1) "1" ["User_id"] => string (1) "1" ["Charge_type"] => string (1) "1" ["Charge_subtype"] => string (1) "1" ["Charge_credits"] => string (3) "100" ["Buy_date"] => string (19) "00:00:00" ["Valid_to"] => string (19) "00:00:00" ["Next_charge_date"] => string (19) "0000-00-00 00:00:00" ["Payment"] => string (6) "paypal" ["Title"] => string (7) "XXXXXXX" } } |