E
E
Evgeniy V.2019-01-23 13:47:26
PHP
Evgeniy V., 2019-01-23 13:47:26

How to make the output of goods on the site, under these conditions?

There is a website and it has several sections. Each such section consists of a set of tabs, in each tab there is a slider, in the slider there are products.
5c4845f88a1ac662787114.jpeg
How to display all these products by category SQL query from the database, in php. I don’t understand what request to make and how to organize a cycle so that products for each category are displayed. At the same time, it is necessary to be able to select these products from the admin panel, but this is another matter.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-01-23
@webinar

How to display all these products by category SQL query

SELECT * FROM someTable 
WHERE category='someCategory'

foreach($products as $product){
...
}

Or separate requests for each category or one request that selects all products, then through array_map or the same cycle, you can collect an array of the form
[
'category_id_1' => [
                                'product1' => [],
                                 ...
                                'product999' => [],
                               ]
'category_id_2' => [
                                'product1' => [],
                                 ...
                                'product999' => [],
                               ]
]

But perhaps it will eat a lot of resources if there are a lot of goods. In the case of a slider, it may make sense to send ajax when clicking on a tab and make the selection you need, return json and build the slider, killing the previous one. Cache requests. Then it will be fast enough to work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question