先说说自己的需求吧——根据标签实现相关文章并实现文章索引,现有三表:文章表(id,title...),标签表(tagid,tag),标签文章对应关系表(aid,tagid):在文章发布页面添加标签字段并把一文章多标签的情况拆分存储进数据库。在不使用explode()的情况下,mysql可以用顺利获取到字段信息和添加的数据信息,但是当使用了explode()后就不可以了,字段信息和value一直为空。问:可以怎么实现一文章多标签以及索引的效果?或者说以下代码可以怎么改善。
$article=i(post.post); $article['eid']=i(post.eid); $tags=i(post.tags); $tags['tag']=explode(,,i(post.tag)); $article['smeta']=json_encode($_post['smeta']); $article['post_content']=htmlspecialchars_decode($article['post_content']); $result=$this->posts_model->add($article); $result2=$this->tags_model->add($tags); echo $this->tags_model->getlastsql(); dump($tags); if ($result && $result2) { $this->tag_relationships_model->add(array(aid=>$result,tagid=>$result2)); foreach ($_post['term'] as $mterm_id){ $this->term_relationships_model->add(array(term_id=>intval($mterm_id),object_id=>$result)); } $this->success(添加成功!); } else { $this->error(添加失败!); } }