• Resolved madsrh123

    (@madsrh123)


    I need to bring the $i to my target page.
    This gives me a list of track titles with a permalink, but on my target page I only get the last $i.

    <?php $args = array( 'post_type' => 'album' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    $i = 1;
    
    	the_title();
    
    	// Gets track ID foreach track
    	while ($i > 0) {
     	   $track = get_field ('track'.$i);
    
     	$permalink = get_permalink( $id );
     	session_start(); // STARTS VARIABLE TO SEND I TO NEXT PAGE
               $_SESSION['variable_name'] = $i;
    
     	   if ($track != '') {
    		echo '<br><a href="' . $permalink . '"><strong>' . $i . ' <strong>' . get_field ('track'.$i) . '</a>';
    		$i++;
    	    }
    	    else {
    	        $i = 0;
    	    }
    	}
    
    endwhile; ?>

    And the target page contains:

    session_start();
    echo $_SESSION['variable_name'];
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Collect the tracks into an interim indexed array. Save the entire array as a session variable when the loop completes. On the target page step through the array with a foreach loop and echo each element in turn.

Viewing 1 replies (of 1 total)
  • The topic ‘$_Session inside while’ is closed to new replies.