SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    PHP Code:
    <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 Code:
    <?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
    PHP Code:
    <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

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    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.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member blogaddition's Avatar
    Join Date
    Sep 2012
    Location
    India
    Posts
    23
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What do you want to do. Please write the exact html code on onclick that you want to write with foreach.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •