osclass / Osclass

With Osclass, get your own classifieds site for free. Build your own Osclass installation and start advertising real estate, jobs or whatever you want- in minutes!
http://osclass.org/
647 stars 343 forks source link

Category filtered popular listings #879

Closed lamas525 closed 11 years ago

lamas525 commented 11 years ago

I asked you for help before 3 days. you answered me with nice code.. it was cool.. ty ... it needed to fix somethink in this code but finaly i did it.. but still doesnt work. any idea? it filter items by category etc. but listings arent ordered.. any idea? Code is here:

function popular_ads_start() {
$mySearch = new Search();
$mySearch->addField("SUM(".DB_TABLE_PREFIX."t_item_stats.i_num_views) as total_views");
$mySearch->addCategory('dvd'); //category
$mySearch->set_rpp(8); //results per page
$mySearch->addTable(DB_TABLE_PREFIX."t_item_stats");
$mySearch->addConditions(DB_TABLE_PREFIX."t_item_stats.fk_i_item_id = ".DB_TABLE_PREFIX."t_item.pk_i_id");
$mySearch->order("i_num_views", "DESC", DB_TABLE_PREFIX."t_item_stats");
$mySearch->addGroupBy(DB_TABLE_PREFIX."t_item_stats.fk_i_item_id");
View::newInstance()->_exportVariableToView("customItems", $mySearch->doSearch());
}
lamas525 commented 11 years ago

Finaly i have it.. issues was in usage " in order and addGroupBy (maybe more, but now its work) .. but sometimes i have issues with bad order.. but 90% of reflashes is order good

conejoninja commented 11 years ago

Hi,

Replace this : $mySearch->order("i_num_views", "DESC", DB_TABLE_PREFIX."t_item_stats");

With this one, sorry I made a mistake : $mySearch->order("total_views", "DESC");

Anyway, as I told you, the problem is that you need to made a sub-query, something like

SELECT * FROM (SELECT * FROM TABLE WHERE CONDITION) WHERE CONDITION)

And ... we're also doing a sub-query in every search, so it should be a sub-sub-query, which could be tricky, but I think that should work