A
A
alestro2015-09-25 10:11:25
PHP
alestro, 2015-09-25 10:11:25

Displaying search results from the index or from the database?

I search the site using sphinx, search the index with all the products, then pull the information from the index into a two-dimensional array as follows:

public function search_query($sql){
    $result = $this->query($sql);
    while ($row = mysqli_fetch_assoc($result)) {
      $search_array[] = $row;
    }
    return $search_array;
  }

Then I output the whole thing in a loop:
for( $i = 0; $i < count($search_array); $i++){ echo $search_array[$i]['id']; }

The question is:
How effective is this method and would it not be better to put only the id of the records in the array and pull out all the products by id from the database in a loop.
And if not, how to organize pagination by array?
Issue resolved.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Akhmetov, 2015-09-25
@asperin2

The only foreach will be both faster and looks somehow better. And so ... one query to the database is better than hundreds.
What is the problem with pagination, you have an index, the easiest way to check

$page = 20;
if ($i%$page == 0) {
Новая страница
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question