<?php
// --------------------------------------------------------------------------
//
// Esvon Classifieds v.4.0
// Copyright(C), Esvon LTD, 2001-2010, All Rights Reserved.
// E-mail: hide@address.com
//
// All forms of reproduction, including, but not limited to, internet posting,
// printing, e-mailing, faxing and recording are strictly prohibited.
// One license required per site running Esvon Classifieds.
// To obtain a license for using Esvon Classifieds, please register at
// http://www.esvon.com/pg/products/p_classifieds/
//
// --------------------------------------------------------------------------
// Random featured listing(s)
function block_Featured_Ad(&$tpl, $args = ''){
global $TITLE_FIELD,$db;
// featured ads amount (to be displayed)
$amt = isset($args['amount']) ? abs(intval($args['amount'])) : 1;
/*
best known speed-up so far:
2 selects: 1/hw_feat="1" AND catid into array 2/link_id AND FilterGet
// Alternative Faster Method ?
// get the highest 2 ids
$res1 = mysql_query("SELECT id FROM table ORDER BY id DESC LIMIT 2");
// generate random no between 0 and second highest id
$top = mysql_result($res1,1);
$rand = rand(0,$top);
// now query for id greater then random no
$sql = "SELECT * FROM table WHERE id>$rand ORDER BY id DESC LIMIT 1"
*/
$ql = "SELECT ".hwSQLFieldsGet()." FROM ".TBL_AD.
" WHERE hw_feat='1'".hwFilterGetSQL();
$ql.=' ORDER BY RAND() LIMIT 0,'.$amt;
$a_v = $db->select($ql);
if(!$a_v) return;
$tpl->AddCell('b_Featured_Ad', '', 'start');
$num = 0;
foreach($a_v as $v){
$v['num'] = ++$num;
$tpl->AddCell('b_Featured_Ad', hwSQLRowGet($v), 'row');
}
}
?>