Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

danimohamadnejad's avatar

should I query to database for all different data on same request?

hello. I want to show types of data in statistics page of website. for instance I want to show a list of latest orders, summary or all orders including total sales, groups sales based on monthes, new users, best selling products and maybe event some other sort of information. my quistion is that is it okay to query them all in my controller method and sent them to view? because I feel these may be to many queries? please guide.

0 likes
4 replies
danimohamadnejad's avatar

yeah thank you. honestly my big worry is that if these kind of requesting all types of essential information is not correct and maybe damages database so I some times think I better request data from inside the view in form of multiple ajax request. what is your opinion about this? can it be good option?

Sinnbeck's avatar

Well personally I use react for most of my apps and therefor often use multiple ajax requests to get different parts of the app at once.. (getting most essential first and the rest afterwards (promise)) But I would say that it depends on what you specific use-case. How to you expect the user to interact with you application

danimohamadnejad's avatar

I think I should do the same using some data first and for remaining queries I will use promises. user should be able to see all data. but I think its no problem if show latest usersa and best sellings a little later than orders summary and chart. thank you

Please or to participate in this conversation.