Discuz! How to write join table queries

Source: Internet
Author: User
There is currently a piece of code like this {code ...} it is used to generate the corresponding ID record in the portal_article_related table after adding relevant articles, and then obtain the related fields in the portal_article_title table through the ID, you also need to use portal_artic... there is currently such a piece of 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;    }    }

It is used to generate the corresponding ID record in the portal_article_related table after adding relevant articles, and then obtain the related fields in the portal_article_title table through the ID, you also need to use the catid in the portal_article_title table to obtain relevant records in the portal_category table. how can I write this?

Thank you.

Reply content:

There is currently such a piece of 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;    }    }

It is used to generate the corresponding ID record in the portal_article_related table after adding relevant articles, and then obtain the related fields in the portal_article_title table through the ID, you also need to use the catid in the portal_article_title table to obtain relevant records in the portal_category table. how can I write this?

Thank you.

Simply write an SQL statement. you don't need to write this AR statement.

Even native SQL statements can be easily implemented

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.