i have also modified the function to stop showing expire ads, code is as bellow
// function for displaying text on the Item page
function popular_ads_start() {
$num_ads = popular_ads_num_ads(); // SETS HOW MANY POPULAR ADS TO DISPLAY
$conn = getConnection();
$results=$conn->osc_dbFetchResults("SELECT fk_i_item_id, i_num_views FROM %st_item_stats ORDER BY fk_i_item_id ASC", DB_TABLE_PREFIX);
if(count($results)>0){
foreach($results as $result){
$view_count[$result['fk_i_item_id']] += $result['i_num_views']; // Add-up all item views stored in database
}
arsort($view_count); // sorts array by highest number of item views first
foreach($view_count as $item_id=>$views)
{
$result=$conn->osc_dbFetchResult("SELECT fk_i_user_id, fk_i_category_id, dt_pub_date, dt_mod_date, f_price, b_active, i_price, fk_c_currency_code, b_premium, s_secret,s_contact_name FROM %st_item WHERE pk_i_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item
$result1=$conn->osc_dbFetchResult("SELECT i_expiration_days FROM %st_category WHERE pk_i_id = %d", DB_TABLE_PREFIX, $result['fk_i_category_id']); //Get expiration days of category
$result2=$conn->osc_dbFetchResult("SELECT DATEDIFF('". date('Y-m-d H:i:s')."','". $result['dt_pub_date']."') as DiffDate"); //Get expiration days difference
$bactive=0;
if($result1['i_expiration_days']==0 || $result2['DiffDate'] <=$result1['i_expiration_days'])
{
$bactive=1;
}
//if($result['b_active']==1){ //if active...
if($bactive==1){ //if active...
//echo 'Item ID: '.$item_id.' Views: '.$views.'<br>'; // display only if item is active
$index++;
// get description
//$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description, s_what FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);
$desc=$conn->osc_dbFetchResult("SELECT fk_c_locale_code, s_title, s_description FROM %st_item_description WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id);
//Get active status of item
$location=$conn->osc_dbFetchResult("SELECT fk_c_country_code, s_country, fk_i_region_id, s_region, fk_i_city_id, s_city FROM %st_item_location WHERE fk_i_item_id = %d", DB_TABLE_PREFIX, $item_id); //Get active status of item
// store the data in an array...
$item_array[] = array('fk_i_user_id'=>$result['fk_i_user_id'],
'fk_i_category_id'=>$result['fk_i_category_id'],
'dt_pub_date'=>$result['dt_pub_date'],
'dt_mod_date'=>$result['dt_mode_date'],
'f_price'=>$result['f_price'],
's_contact_name'=>$result['s_contact_name'],
'fk_i_item_id'=>$item_id,
'pk_i_id'=>$item_id,
'b_active'=>$result['b_active'],
'i_price'=>$result['i_price'],
'fk_c_currency_code'=>$result['fk_c_currency_code'],
'b_premium'=>$result['b_premium'],
'fk_c_locale_code'=>$desc['fk_c_locale_code'],
's_title'=>$desc['s_title'],
's_description'=>$desc['s_description'],
's_what'=>$desc['s_what'],
'fk_c_country_code'=>$location['fk_c_country_code'],
's_country'=>$location['s_country'],
'fk_i_region_id'=>$location['fk_i_region_id'],
's_region'=>$location['s_region'],
'fk_i_city_id'=>$location['fk_i_city_id'],
's_city'=>$location['s_city'],
's_secret'=>$result['s_secret'],
'locale'=>array('en_US'=>array('fk_i_item_id'=>$item_id,
'fk_c_locale_code'=>$desc['fk_c_locale_code'],
's_title'=>$desc['s_title'],
's_description'=>$desc['s_description'],
's_what'=>$desc['s_what']
)
)
);
}
if($index>=$num_ads) break; // limit number of ads to display
}
GLOBAL $stored_items;
$stored_items = View::newInstance()->_get('items') ; //save existing item array
View::newInstance()->_exportVariableToView('items', $item_array);
} else echo 'No Results.';
}