M
M
Max Ba2018-04-23 15:08:10
PHP
Max Ba, 2018-04-23 15:08:10

How to get both an array of goods and quantity?

Good afternoon. It is necessary to display the products on the page, as well as under them the total number of products found (the condition changes). Products are displayed 30 per page.
You have to make two requests. The first outputs the array of goods itself, limiting it with LIMIT. The second count(*) with the same conditions as the first request. I heard that PDO can somehow work without LIMIT. Does it make sense to redo it (if it is of course possible) or am I right and so I deduce?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
F
FanatPHP, 2018-04-23
@FanatPHP

PDO does not write SQL for you. It can only fulfill the request that you yourself were able to write. Therefore, the phrase "PDO can somehow work without LIMIT" does not make sense.
So leave requests as they are.
It always makes sense to remake it under PDO if you now have a standard shit code like "Peter has 2 apples, and Vasya has 5": while mysql_fetch_array and that's it.
If SQL_CALC_FOUND_ROWS will be pushed to you - don't get fooled, it is certainly slower than count (*) and still 2 queries.

A
anyd3v, 2014-04-18
@anyd3v

sublime text 3

1
1001001 111, 2014-04-18
@IgorO2

Sublime Text 3

V
v_prom, 2014-04-18
@v_prom

vim

G
GM2mars, 2014-04-18
@GM2mars

Sublime text 2, the third one is outrageously buggy.

N
Nikolai Vasilchuk, 2014-04-18
@Anonym

The choice depends on the programming language.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question