get_row("SELECT * FROM ".$wpdb->prefix."allvideogallery_profiles WHERE id=".$profileid); $query = "SELECT * FROM ".$wpdb->prefix."allvideogallery_videos WHERE published=1"; if( isset($_GET['slg']) ) { $slug = $_GET['slg']; $query .= " AND slug!='$slug'"; } if($catid) { $gallery = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."allvideogallery_categories WHERE id=".$catid); $query .= " AND category='$gallery->name'"; } switch($sort) { case 'latest' : $query .= ' ORDER BY id DESC'; break; case 'popular' : $query .= ' ORDER BY hits DESC'; break; case 'random' : $query .= ' ORDER BY RAND()'; break; case 'featured' : $query .= ' AND featured=1 ORDER BY ordering'; break; default : $query .= ' ORDER BY ordering'; break; } $videos = $wpdb->get_results($query); $custid = ( $profile->custom_gallery_id ) ? $profile->custom_gallery_id : 'avs_gallery'; $limit = $profile->rows * $profile->cols; $total = ceil( count($videos) / $limit ); $start = max(1, $_GET['start']); $limitstart = ($start - 1) * $limit; $limitend = $start * $limit; if(count($videos) < $limitend) $limitend = count($videos); $output = ''; $output .= '