Bonjour à tous !
Voila, depuis un petit moment je chercher à trouver une solution à mon problème que voici:
Sur mon site (encore en developpement) j'ai une page personnalisé pour chaque vidéo (ex: www.monsite.com/video.php?id=2) bref, rien de bien compliqué, mais en bas de cette page, j'aimerais avoir 3 vidéos au hasard.
Dans la BDD, j'ai une table video avec un id pour chacune de mes vidéos puis l'id youtube de la video.
Je voudrais faire une requete SQL qui me permet de prendre 3 lignes au hasard dans ma table vidéo. et c'est là où est le probleme !!!
<?php
$allVideoRecommended = $bdd->prepare("SELECT * FROM video WHERE id_video=?");
$allVideoRecommended->execute(array($id_alea_video));
?>
il faut que le nombre au hasard corresponde à un VRAI id qui existe.
J'espère avoir été claire ^^
sinon voici mon code mais j'ai une erreur:
<div class="block_videos_recommandees">
<h3>Vidéos recommandées</h3>
<?php
$id_all_video = $bdd->query("SELECT id_video FROM video");
$id_all_video = $id_all_video->fetchAll();
$id_alea_video = array_rand($id_all_video, 3);
$id_alea_video = implode("", $id_alea_video);
$id_alea_video1 = substr($id_alea_video, 0, 1);
$id_alea_video2 = substr($id_alea_video, 1, 1);
$id_alea_video3 = substr($id_alea_video, 2, 1);
$videoRecommended1 = $bdd->prepare("SELECT * FROM video WHERE id_video=?");
$videoRecommended1->execute(array($id_alea_video1));
$recommended1 = $videoRecommended1->fetchAll();
$videoRecommended2 = $bdd->prepare("SELECT * FROM video WHERE id_video=?");
$videoRecommended2->execute(array($id_alea_video2));
$recommended2 = $videoRecommended2->fetchAll();
$videoRecommended3 = $bdd->prepare("SELECT * FROM video WHERE id_video=?");
$videoRecommended3->execute(array($id_alea_video3));
$recommended3 = $videoRecommended3->fetchAll();
var_dump($recommended1);
?>
<div style="display: inline-block; width: 33%;text-align: center;">
<a href="/mozorstudio/formations/<?= secur_get($recommended1['0']['small_title_video'])?>-<?= $recommended1['0']['id_video']?>">
<img class="image_video" style="width: 80%;" src="http://i.ytimg.com/vi/<?= $recommended1['id_youtube_video']?>/mqdefault.jpg" />
</a>
</div>
<div style="display: inline-block; width: 33%;text-align: center;">
<a href="/mozorstudio/formations/<?= secur_get($recommended2['small_title_video'])?>-<?= $recommended2['id_video']?>">
<img class="image_video" style="width: 80%;" src="http://i.ytimg.com/vi/<?= $recommended2['id_youtube_video']?>/mqdefault.jpg" />
</a>
</div>
<div style="display: inline-block; width: 33%;text-align: center;">
<a href="/mozorstudio/formations/<?= secur_get($recommended3['small_title_video'])?>-<?= $recommended3['id_video']?>">
<img class="image_video" style="width: 80%;" src="http://i.ytimg.com/vi/<?= $recommended3['id_youtube_video']?>/mqdefault.jpg" />
</a>
</div>
</div>