php - How to order items on an online store by popularity -


i have series of items displayed on homepage, want order popularity. have column called sales, counter how many sales product has.

how can use and/or other columns determine items display on homepage? can't use sales search popular items, because items sales dominate homepage - want balanced query.

if possible query should occur within timeframe, example past week etc.

here's query:

$popular_items = db::fetch("select * `products` order `sales` desc limit 10"); 

you have define "popularity" first: views, sales, or number of counts in shopping carts?

assuming have 2 factors: pageview , sales. can order these factors ratio, respect "fresh period":

select * `products`  datediff(last_update_date, curdate()) < 30 order (pageview * 0.7 + sales * 0.3) desc 

something (as don't know column names in table)


if want have balanced results, can use:

select * `products` order rand() desc 

which return random results. need limit (pointless list out products).

side note:

  • it suggested select useful columns (avoid using select *)

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -