On OLX like Website , Anytime a user posts a new ad. It comes in top of the page. No search is involved in it. Which technology we can use to make such functions.
Suppose X is visiting my website abc.com. Should I fetch database each time and generate page dynamically ?
or There is a better approach to to that.
Ques no 2. Suppose X is searching a ad on my website abc.com. Should I run sql query on my database every time ?
Please guide me.
-
3Basically you would have to generate it dynamically of course. Though in this case you could cache the page or parts of it. For the search part you would most likely want to use a search engine like Elasticsearch or Apache Solr.thorsten müller– thorsten müller2016年06月08日 07:35:35 +00:00Commented Jun 8, 2016 at 7:35
1 Answer 1
Usually you have to query DB every time you render a page.
Q1 - Yes, you just have to select all items ordered by created date (well, you don't want to select ALL, but only how much you need for current page - see 'Pagination')
Q2 - Yes. Same as above. This might not work exactly as you want, because SQL databases are not search engines. In SQL DB you can only do simple search and filter. If you need better searching methods (search even when typos are present, ranking results, similar items, etc.) then you need search engine - Apache Solr for example)
Don't worry about querying database. It's designed to do this :) Start worrying about performance when you really fell page is running slow. When it happens you can start thinking about using 'cache' to store some database queries results.
EDIT - it's best to use some php framework to help you with some of this ;)
Explore related questions
See similar questions with these tags.