Reputation: 1067
i made a video.php page that will show the videos from youtube depending on id of the video on youtube,so i made something like that
if($_GET['id']=="jquery11"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/6PM6t5RFR2w?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery12"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/fE0GC7KFIno?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery13"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/xuFa2R4c6Gc?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery14"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/M971xYWiS7M?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery15"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/oZ_J422z4WI?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery16"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/tYJMitUfSvs?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery17"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/wZPhQzqGzls?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery18"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/Cdwn2JoCYQ0?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
if($_GET['id']=="jquery19"){
?>
<div id="video" ><iframe width="640" height="360" src="http://www.youtube.com/embed/cKCiNf23Atg?autoplay=1&controls=2" frameborder="5" allowfullscreen></iframe></div>
<?
}
?>
any idea to change this method that will decrease get requests?i tried making associative array ,but i think it's same
Upvotes: 1
Views: 92
Reputation: 140228
$map = array(
"jquery11" => "6PM6t5RFR2w",
"jquery12" => "fE0GC7KFIno",
"jquery13" => "xuFa2R4c6Gc",
"jquery14" => "M971xYWiS7M",
"jquery15" => "oZ_J422z4WI",
"jquery16" => "tYJMitUfSvs",
"jquery17" => "wZPhQzqGzls",
"jquery18" => "Cdwn2JoCYQ0",
"jquery19" => "cKCiNf23Atg"
);
$id = $_GET['id'];
if( array_key_exists( $id, $map ) ) {
echo <<<HTML
<div id="video" >
<iframe width="640" height="360" src="http://www.youtube.com/embed/{$map[$id]}?autoplay=1&controls=2" frameborder="5" allowfullscreen>
</iframe>
</div>
HTML;
}
Upvotes: 3
Reputation: 1847
Untested - should work tho:
<?php
$request = $_GET['request'];
$accepted_requests = array(1 =>'jquery1', 2 => 'jqery2', 3 => 'jquery3');
$utube_urls = array(1 => 'url', 2 => 'url', 3 => 'url');
if(in_array($request, $accepted_requests)){
foreach($accepted_requests as $k=>$v){
if($request === $v){
foreach($utube_urls as $keys => $vals){
if($k == $keys){
echo $vals;
}
}
}
}
}
?>
UPDATED THE CODE: Missed the 's' on $val - fixed now
Upvotes: 1
Reputation: 1847
Create an array of your possible ids, and then check if the variable being passed is in the array by using in_array under an if statement, and then just assign the proper url from there.
Upvotes: 1