mercredi 28 septembre 2016

Random Video via MySQL

I have a MySQL database in which i store the URL to 8 videos. What i want to do know is display them random in a slider. It's alls working until now, besides that the Video is not random but all the time the same, which means: The video gets randomly picked from the database, but each time i refresh the page, it's 8 times video number 1, next refresh is 8 times number 6 etc.

<?php                            $mysqli = new mysqli("####", "####", "###", "clearchannel");
                                 if ($mysqli->connect_errno) {
                                 echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
                                 }                      

                                $res = $mysqli->query("SELECT EmbedURL FROM Videos where location_id='2' ORDER BY RAND() LIMIT 3");
                                $vid = $res->fetch_assoc();
                            ?>  
                        <ul class="bxslider">
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                            <li><iframe src="<?php echo $vid['EmbedURL']; ?>" frameborder="0" autoplay="0" allowfullscreen></iframe></li>
                        </ul>           

?>

You can see the result here: http://ift.tt/2dlvL1D

Thanks a lot!




Aucun commentaire:

Enregistrer un commentaire