embedding shortcodes in php template

I think it needs to be like this:

<?php $output="[accordion]"; ?>  
            <?php                                                     
                $args = array(
                                'posts_per_page' => '-1',
                                'post_type' => 'post',
                                'post_status' => 'publish',
                                'category__in' => $quicksand_categories 
                                );                     
                $query = new WP_Query( $args );                                             
                foreach ($query->posts as $item) {                      
                    $categories = wp_get_post_categories($item->ID);
                    ?>
<?php $output.='[accordion-item title="'.get_the_title($item->ID).'"]'.the_content().'[/accordion-item]'; ?>                   

                <?php  }  ?>
<?php $output .= '[/accordion]'; ?>
<?php echo do_shortcode($output); ?>