Discuz! How to write a joint table query

WBOY
Release: 2023-03-02 11:52:01
Original
1365 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template