Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8486301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:54:20+00:00 2026-06-10T20:54:20+00:00

I have this php/html code which loads a random youtube video from a php

  • 0

I have this php/html code which loads a random youtube video from a php array each time the page is loaded. But I want to have next and previous buttons to load the next and previous videos in the array. Only a single video must be loaded at any time. I have this:

<?php $videos = array("0jBRY_Aki9s","1czXvHSjDac","1kbiUiRfnh8","377kKBi6anQ"); 

$rand = array_rand($videos); 
$rand_key = $videos[$rand]; 
$numOfItems = count($videos);

echo "<iframe width='375' height='310' 
src='http://www.youtube.com/embed/$rand_key?&amp;fmt=22&amp;autoplay=1'> </iframe>";?> 

<span onclick="<?php $clip = next($videos); 
echo "<iframe style='float:left;' width='375' height='310' 
src='http://www.youtube.com/embed/$clip?&amp;fmt=22&amp;autoplay=1'>
</iframe>";?> ">next</span>

Is there some way to use the php “next” method to do change the current video on the iframe ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:54:22+00:00Added an answer on June 10, 2026 at 8:54 pm

    No! You cannot mix PHP with Javascript like that, PHP is server side while Javascript is client side, based on browser.
    You have 2 options, you can use AJAX to load next video, or use an anchor to link to next video:

    <?php
        $videos = array("0jBRY_Aki9s" , "1czXvHSjDac" , "1kbiUiRfnh8" , "1uTypnaP5X4" , "377kKBi6anQ"); 
        $rand = array_rand($videos);
        $rand_key = isset($_GET['id']) ? $_GET['id'] : $rand;
    
        echo "<iframe width='375' height='310' src='http://www.youtube.com/embed/".$videos[$rand_key]."?&amp;fmt=22&amp;autoplay=1'> </iframe>";
    
        $next = isset($videos[($rand_key+1)]) ? ($rand_key+1) : 0;
        $prev = isset($videos[($rand_key-1)]) ? ($rand_key-1) : count($videos)-1;
    ?> 
    
    <a href="test.php?id=<?php echo $prev; ?>">prev</a> | <a href="test.php?id=<?php echo $next; ?>">next</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

index.php has this jquery code which loads notifications.inc.php into a div on the page
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have this code snippet in an email layout: <div> <?php echo $this->Html->image('Layouts/default/Logo.png', array(
I have a line of php code that looks like this: echo <script>$('#edit_errors').html('<h3><em>Please Correct
I have this PHP script which i'm grabbing images from a directory and displaying
I have this page which loads quotes. It has a search form wherein if
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
Often when writing PHP I'll have it output some HTML like this - echo
I have this PHP code to highlight the Query on search results. if (isset($_REQUEST['k'])){
I have this PHP page where the user can select and un-select items. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.