R
R
ravshan selimov2020-05-18 19:10:17
PHP
ravshan selimov, 2020-05-18 19:10:17

How to implement search by several keywords in the database?

How to implement search by multiple keywords from a table.
Requires sorting by time and a certain amount.
I am using redbeanphp.

I do a single label search like this:

$posts_labels = R::findAll('postslabels', 'label = ? ORDER BY `time` DESC LIMIT {$start},{$end}', [$search_text]);
  $posts  = [];

  foreach ($posts_labels as $value) {
    $id = $value->post_id;
    $post = R::findOne('posts', "id = ?", [$id]);
    $posts[] = $post;
  }


how to search for 2 or 3 keywords

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
runapa, 2020-05-18
@ravshan01

Try the R::getAll(); You can write native sql in it, and everything is already there as usual:

SELECT field FROM table WHERE keyword LIKE %keyword% OR keyword2 LIKE %keyword2%...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question