$query = "SELECT * FROM ".$this->getPrefix()."mylinks WHERE blog_id = ".$blogId; if( $categoryId != 0 ) $query .= " AND category_id = ".$categoryId; $query .= " ORDER BY id ASC;";