-- --The structure of the table ' Charge_logs ' --
CREATE TABLE IF not EXISTS ' charge_logs ' ( ' id ' int (one) not NULL auto_increment, ' charge_id ' int (one) is not NULL, ' title ' Text not NULL, PRIMARY KEY (' id ') ) Engine=innodb DEFAULT Charset=utf8 auto_increment=2;
-- --the data in the Dump table ' Charge_logs ' --
INSERT into ' charge_logs ' (' id ', ' charge_id ', ' title ') VALUES (1, 1, ' XXXXXXX ');
-- --The structure of the table ' User_charges ' --
CREATE TABLE IF not EXISTS ' user_charges ' ( ' ID ' int (a) unsigned not NULL auto_increment, ' user_id ' int (a) 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 ' 0000-00-00 00:00:00 ', ' valid_to ' timestamp not NULL DEFAULT ' 0000-00-00 00:00:00 ', ' Next_charge_date ' timestamp not NULL DEFAULT ' 0000-00-00 00:00:00 ', ' Payment ' varchar not NULL, PRIMARY KEY (' id ') ) Engine=innodb DEFAULT Charset=utf8 auto_increment=2;
-- --the data in the Dump 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,, ' 2011-09-09 00:00:00 ', ' 2011-09-16 00:00:00 ', ' 0000-00-00 00:00:00 ', ' PayPal '); Using a select query in Zend_db_table_abstract $select = $this->getadapter ()->select (); $select->from (' UC ' => ' user_charges ')) ->joinleft (' cl ' => ' charge_logs '), ' uc.id = cl.charge_id ', array (' title ')) ->where (' uc.user_id=? ', $id); return $this->getadapter ()->fetchall ($select); If you are using a mapper, you can use this $select = $this->getdbtable ()->getadapter ()->select (); $select->from (' UC ' => ' user_charges ')) ->joinleft (' cl ' => ' charge_logs '), ' uc.id = cl.charge_id ', array (' title ')) ->where (' uc.user_id=? ', $id);
return $this->getdbtable ()->getadapter ()->fetchall ($select); Output results Array (1) { [0] => Array { [id] => string (1) "1" [ user_id "] => string (1)" 1 " [" Charge_type "] => string (1)" 1 " [" Charge _subtype "] => string (1)" 1 " [" Charge_credits "] => string (3)" M " [" Buy_date "] => string (a)" 2011-09-09 00:00:00 " [" valid_to "] => string (19)" 2011-09-16 00:00 : " [next_charge_date] => string" 0000-00-00 00:00:00 [" Payment "] => string (6)" PayPal " [" title "] => string (7)" XXXXXXX " } } |