sql - zend retriving tag list -


i have problem zend. here is. i'm going make kind of articles db, containt info. every article marked 1 or more tags (like wordpress).

i have controller (let index) , action (also index). need articles , tags, associated it, when user goes site/index/index.

i have 3 tables:

articles(idarticles, title..) tags(idtags, title) taglist(idarticles, idtags). 

how can read tags, associated article?

zend's mvc doesn't include model, however, quickstart guide outlines creating model.

the simplest way (not best way), setup connection in application.ini, or setup adapter (see zend_db_adapter docs):

$db = new zend_db_adapter_pdo_mysql(array(   'host'     => '127.0.0.1',   'username' => 'webuser',   'password' => 'xxxxxxxx',   'dbname'   => 'test' )); 

then use sql select data.

//all articles $articles = $db->query('select * articles'); //a article's tags $tags = $db->query('select * taglist join tags on          (taglist.idtag = tags.idtags) idarticles = ?', $idarticles); 

this taged zend_db_table, use access data, first setup default adapter (or again, use application.ini):

zend_db_table::setdefaultadapter($dbadapter); 

then objects tables this:

$ariclestable = new zend_db_table('articles'); 

to articles:

$articles = $articlestable->fetchall(); 

to article's tags (little more complex here, using zend_db_table_select recommended):

$select = $tagstable->select(); //3rd argument must empty array, no joined columns selected $select->join('taglist', 'taglist.idtag = tags.idtags', array());  $select->where('taglist.idarticles = ?', $idarticles); $tags = tagstable->fetchall($select); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -