Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Losowe iframe
rafalgt
post 23.06.2014, 06:51:35
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 5.10.2013

Ostrzeżenie: (0%)
-----


Witam.

Mam na stronie umieszczony iframe z filmem youtube. Chciałbym zrobić losowe wyświetlanie takich kilku filmów.

W tym momencie kod przy filmie wygląda tak:

  1. echo "<div id='movie'> ";
  2.  
  3. echo"<iframe width='240' height='185' src='//www.youtube.com/embed/DuHz_k3UNes?rel=0' frameborder='0' ></iframe>";
  4.  
  5.  
  6. echo"<iframe src='http://dix-racing.pl/RFE_P/RFE_simple_forecast.php' height='20px' width='1000' scrolling='no' frameborder='0' style='margin-top: 58px;margin-left: -9px;'></iframe>";
  7.  
  8.  
  9. echo "</div>";


Pomógłby ktoś napisać kod tak aby dodać jeszcze 3 linki z youtube i aby były wyświetlane losowo na stronie.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
gitbejbe
post 23.06.2014, 09:26:01
Post #2





Grupa: Zarejestrowani
Postów: 516
Pomógł: 63
Dołączył: 27.08.2012

Ostrzeżenie: (0%)
-----


  1. $filmiki = array('filmik 1', 'filmik 2', .... , 'filmik 1001');
  2. $losuj = array_rand($filmiki, 3);
  3.  
  4. foreach($losuj as $link){
  5. echo"<iframe width='240' height='185' src='".$link."' frameborder='0' ></iframe>";
  6. }


Ten post edytował gitbejbe 23.06.2014, 09:29:27
Go to the top of the page
+Quote Post
rafalgt
post 23.06.2014, 13:32:46
Post #3





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 5.10.2013

Ostrzeżenie: (0%)
-----


Czy to ma wyglądać tak?

  1. $filmiki = array('http://www.youtube.com/embed/DuHz_k3UNes?rel=0', 'http://www.youtube.com/embed/DuHz_k3UNes?rel=0', 'http://www.youtube.com/embed/DuHz_k3UNes?rel=0');
  2. $losuj = array_rand($filmiki, 3);
  3.  
  4. foreach($losuj as $link){
  5. echo"<iframe width='240' height='185' src='".$link."' frameborder='0' ></iframe>";
  6. }
Go to the top of the page
+Quote Post
gitbejbe
post 23.06.2014, 13:48:59
Post #4





Grupa: Zarejestrowani
Postów: 516
Pomógł: 63
Dołączył: 27.08.2012

Ostrzeżenie: (0%)
-----


a co nie masz na czym tego odpalić ? ludzie błagam o trochę samodzielności...

ps. zrobiłem błąd, w miejsce echo"<iframe width='240' height='185' src='".$link."' frameborder='0' ></iframe>";
należny wstawić $filmiki[$link]. I jeśli w tablicy masz 3 elementy, to w array_rand wpisz 2 zamiast 3

Ten post edytował gitbejbe 23.06.2014, 13:53:19
Go to the top of the page
+Quote Post
rafalgt
post 23.06.2014, 13:59:52
Post #5





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 5.10.2013

Ostrzeżenie: (0%)
-----


Problem rozwiązany dzięki znajomemu.


  1. $filmiki = array('http://www.youtube.com/embed/DuHz_k3UNes?rel=0', 'http://www.youtube.com/embed/RHsiU34gA2k?rel=0');
  2. shuffle($filmiki);
  3. echo"<iframe width='240' height='185' src='".$filmiki[0]."' frameborder='0' ></iframe>";
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 08:47