A
A
Arthur Strezhinov2017-09-16 18:37:44
Yii
Arthur Strezhinov, 2017-09-16 18:37:44

How to search in two tables, they are different?

I am doing a normal search, there are two tables articles and video_articles, everything is simple with the first table, there I am looking for titles (title), how to search for another video_articles table also by titles?
actionSearch

public function actionSearch()
    {
        $similarArticles = Articles::getSimilarArticles();
        $q = Yii::$app->request->get('q');
        $query = Articles::find()->where(['like', 'title', $q])->asArray();
        $pages = new Pagination(
            [
                'totalCount' => $query->count(),
                'pageSize' => 2,
                'forcePageParam' => false,
                'pageSizeParam' => false,
            ]
        );
        $articles = $query->offset($pages->offset)->limit($pages->limit)->all();

        return $this->render('search',
            [
                'articles' => $articles,
                'pages' => $pages,
                'q' => $q,
                'similarArticles' => $similarArticles,

            ]);
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2017-09-16
@BorisKorobkov

Option 1. SELECT ... UNION SELECT ...
Option 2. Search separately, then combine 2 arrays
Option 3. Sphinx, Lucene, etc.

A
Alexander Aksentiev, 2017-09-16
@Sanasol

https://stackoverflow.com/questions/5859391/create...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question