最模板抽空做了个函数:
function get_position_ads($id) { $sql = "select * from " . $GLOBALS['ecs']->table('ad') . " where position_id = ".$id." AND enabled = 1 order by ad_id"; $rows = $GLOBALS['db']->getAll($sql); if($rows ) { $sql = "select ad_width,ad_height from " . $GLOBALS['ecs']->table('ad_position') . " where position_id = ".$id." limit 1"; $ad_position = $GLOBALS['db']->getRow($sql); foreach($rows as &$row ) { $row['pic']= 'data/afficheimg/'.$row['ad_code']; $row['width'] = $ad_position['ad_width']; $row['height'] = $ad_position['ad_height']; } } return $rows; }