1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is there php code that will do this ...

Discussion in 'PHP & Perl' started by equalizer, Jun 29, 2011.

  1. equalizer

    equalizer Junior Member

    Joined:
    Jul 20, 2008
    Messages:
    150
    Likes Received:
    64
    Can some programmer genius write me some php code for my blog that will fetch a different video from youtube or other leading video servers every time the page loads.
     
  2. hi.imandrew

    hi.imandrew Junior Member

    Joined:
    Nov 22, 2009
    Messages:
    159
    Likes Received:
    42
    Location:
    Arkansas, USA
    • Thanks Thanks x 1
  3. eskimo

    eskimo Regular Member

    Joined:
    Dec 1, 2008
    Messages:
    474
    Likes Received:
    178
    do you just want a random video, or from a specific list of videos?
     
    • Thanks Thanks x 1
  4. equalizer

    equalizer Junior Member

    Joined:
    Jul 20, 2008
    Messages:
    150
    Likes Received:
    64
    Random please.
     
  5. equalizer

    equalizer Junior Member

    Joined:
    Jul 20, 2008
    Messages:
    150
    Likes Received:
    64
  6. eskimo

    eskimo Regular Member

    Joined:
    Dec 1, 2008
    Messages:
    474
    Likes Received:
    178
    If you have a few randoms, you can do (php):
    Code:
    $random = rand(0,5);
    	
    	if ($random == 0){
    		//video 1
    	}
    	
    	if ($random == 1){
    		//video 2
    	}
    
    etc...
    
    if they coming from a database its pretty much the same, just your query will change basedon the random number. this depends on how your DB structure

    PM me if you need help with anything
     
    • Thanks Thanks x 1
  7. equalizer

    equalizer Junior Member

    Joined:
    Jul 20, 2008
    Messages:
    150
    Likes Received:
    64
    Thank you Eskimo, I will try it and report.
     
  8. killobyte

    killobyte Newbie

    Joined:
    Jul 1, 2011
    Messages:
    1
    Likes Received:
    0
    you could also scrape a lot of urls, using scrapebox or something similar, then put them into a mysql db, then have php grab a random row from the db.

    More efficient and you could have literally millions in there.

    Then you could append to that list of urls whenever you wanted, scrape new ones and dump in there, and you could scrape videos that were specifically related to the niche.

    I'd post the code but it blocks me because im new.

    mysql has a query in select where you do a "select from db order by rand() limit 1" then the resulting output is a random row, without using random number function or having access to the other rows in memory.
     
    Last edited: Jul 1, 2011