Answer the question
In order to leave comments, you need to log in
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
Option 1. SELECT ... UNION SELECT ...
Option 2. Search separately, then combine 2 arrays
Option 3. Sphinx, Lucene, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question