Home  >  Article  >  Backend Development  >  Discuz! How to write a joint table query

Discuz! How to write a joint table query

WBOY
WBOYOriginal
2016-12-01 01:27:341311browse

Currently there is a piece of code like this

<code>$article['related'] = array();
if(($relateds = C::t('portal_article_related')->fetch_all_by_aid($aid))) {
    foreach(C::t('portal_article_title')->fetch_all(array_keys($relateds)) as $raid => $value) {
        $value['uri'] = fetch_article_url($value);
        $article['related'][$raid] = $value;
    }
    
}</code>

Its function is to generate ID corresponding records in the portal_article_related table after adding related articles, and then obtain the relevant fields in the portal_article_title table through the ID. Now I want to build on this, and also need to obtain the portal_category through the catid in the portal_article_title table. How to write the relevant records in the table?

Thank you.

Reply content:

Currently there is a piece of code like this

<code>$article['related'] = array();
if(($relateds = C::t('portal_article_related')->fetch_all_by_aid($aid))) {
    foreach(C::t('portal_article_title')->fetch_all(array_keys($relateds)) as $raid => $value) {
        $value['uri'] = fetch_article_url($value);
        $article['related'][$raid] = $value;
    }
    
}</code>

Its function is to generate ID corresponding records in the portal_article_related table after adding related articles, and then obtain the relevant fields in the portal_article_title table through the ID. Now I want to build on this, and also need to obtain the portal_category through the catid in the portal_article_title table. How to write the relevant records in the table?

Thank you.

Just write the SQL statement directly, there is no need to use this AR writing method.

Even native sql statements should be easy to implement

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP output imageNext article:PHP output image