Foreach inside while loop

Hi i am trying to add a for each inside a while loop this is how I want to work the while loop retrieve the above from the database

<li><a href="#tabs-<?php echo get_the_ID(); ?>" onclick="jwplayer('mediaplayer_vid_1').stop();jwplayer('mediaplayer_vid_2').stop();jwplayer('mediaplayer_vid_3').stop();jwplayer('mediaplayer_vid_4').stop();"><?php  echo get_the_post_thumbnail( $post_id, 'story-thumbnail'); ?></a></li>

so it display the above various time

But I am trying to achive the above plus a the foreach inside the onclick because i want to for each post to increment the number inside the onclick mediaplayer_vid_1, mediaplayer_vid_2, mediaplayer_vid_3

so i have the foreach loop that increment by 1

<?php foreach ($posts as $post) $post_count++; ?>
                  <?php echo "jwplayer('mediaplayer_vid_3').stop()". $post_count; ?>

I want that to be inside the onclick
I have tried like this but does not work anyone can help me out

<li><a href="#tabs-<?php echo get_the_ID(); ?>" onclick="<?php foreach ($posts as $post) $post_count++;  echo "jwplayer('mediaplayer_vid_ '.$post_count.').stop()"; ?>><?php  echo get_the_post_thumbnail( $post_id, 'story-thumbnail'); ?></a></li>

Thanks in advance

get the number of posts beforehand and do it witha for loop would be my primary suggeestion.

As to why your code doesnt work… put { } around your two statements. If you dont, the foreach will execute only the first statement.

What do you want to do. Please write the exact html code on onclick that you want to write with foreach.