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

  • Home
  • SEARCH
  • 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 6533687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:09:30+00:00 2026-05-25T10:09:30+00:00

I am creating a website that gets random videos from the db. My problem

  • 0

I am creating a website that gets random videos from the db.
My problem is that my code to get the random video is this:

select id,content from videos order by rand() limit 1

And I don’t want the user to see the same video until 3 other videos (at least) were played before.

Do you have any suggestion on how to do that?
This is how my site works currently.

  1. HTML-AJAX(CALL FOR VIDEO URL)
  2. PHP(RETURN RANDOM VIDEO URL) One video.
  3. AJAX(DISPLAY VIDEO)

[EDITED]
Another problem I am facing is that I need to return only one video url,
because this is how my ajax call look like:

success: function(data){

            $('#content').html('<div id="ytapiplayer">You need Flash player 8+ and JavaScript enabled to view this video.</div>');
            var params = { allowScriptAccess: "always" };
            var atts = { id: "ytapiplayer" };
            swfobject.embedSWF(data.vidData+"&enablejsapi=1&playerapiid=ytapiplayer?autoplay=1", "ytapiplayer", "500", "405", "8", null, null, params, atts);
}

Thanks in advance.

  • 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-05-25T10:09:30+00:00Added an answer on May 25, 2026 at 10:09 am

    Could the video id be sent to the client? Then from there the client (Javascript) request the video. Here how that could be played:

    1. Ajax the the list of video ids
    2. insert them in an Array in javascript (var toWatch)
    3. Random the array
    4. Get the first video
    5. Remove the id from the first array. You might want to keep a trace of that id in an other array
    6. repeat 4-5

    In javascript it might look like :

    $.post("getVideoId.php",function(videoId){
       var aVideoToWatch = videoId.split(',').sort(randOrd);
    
       for(var x=0; x<aVideoToWatch.length;x++){
           $.post("getAVideo(aVideoToWatch[x])",function(){
               //play the video
           })
       }
    })
    
    // source : http://javascript.about.com/library/blsort2.htm
    function randOrd(){
     return (Math.round(Math.random())-0.5); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that right now, runs by creating static html pages from
I was creating a website http://tapasya.co.in and i found that this site has some
I am creating a website that pulls data from a CSV file and then
I am creating an website that will allow users too create there own blog/Content
I am creating a website that has 5 different sub-sites each with the same
I am creating a website that uses a fluid layout with artificial columns. I
I'm creating an installer for a website that uses a custom event log source.
I am creating an ASP.Net MVC website that I am launching soon in private
Are there any good books or website that go over creating a JTable ?
I'm creating a website that will be in English, Chinese and Korean. There are

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.