Junaid R Posted November 13, 2014 Share Posted November 13, 2014 <?php $game = $_GET["id"]; if ($game == ballpool) { <div id="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"></div>; } elseif ($game == minisoccer) { <div id="miniclip-game-embed" data-game-name="soccer-stars" data-theme="0" data-width="750" data-height="450" data-language="en"></div> } else { echo "Invalid Request"; } ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted November 13, 2014 Share Posted November 13, 2014 Do you have a question? 1 Link to comment Share on other sites More sharing options...
Junaid R Posted November 13, 2014 Author Share Posted November 13, 2014 well.. yes. i have gaminig website. and i've made just one page for playing online for all games. i have used this php syntax in my page to get variable from the url and compare it with the if statements and execute the true code block. this code works fine when i replace the <div id="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"></div>; thing with echo "Whatever"; it works fine then.. Link to comment Share on other sites More sharing options...
thescientist Posted November 13, 2014 Share Posted November 13, 2014 As alluded to, what kind of help are you looking for? As general observations, I will say that The if statement is incorrect, ballpool and minisoccer should be in quotes Your markup also needs to be in quotes You are repeating markup generation that you only need to do once. Perhaps something like this (which is easily extendable) <?php$game = $_GET["id"]; //make an array to store all specific properties of each game$gamesConfig = array( "ballpool" => array( "name" => "8-ball-pool-multiplayer" "height" => 520 ), "minisoccer" => array( "name" => "soccer-stars" "height" => 450 )); $output = ''; //test that the game provided existsif ($gamesConfig[$game]) { //get the config for the game $config = $gamesConfig[$game]; //build up the HTML using values from the config $output .= '<div id="miniclip-game-embed" data-game-name="' . $config["name"] . '" '; $output .= 'data-theme="0" data-width="750" data-height="' . $config["height"] . '" '; $output .= 'data-language="en"></div>';} else { $output = "Invalid Request";} echo $output; ?> 1 Link to comment Share on other sites More sharing options...
Junaid R Posted November 13, 2014 Author Share Posted November 13, 2014 thanx (Y) let me try Link to comment Share on other sites More sharing options...
Junaid R Posted November 13, 2014 Author Share Posted November 13, 2014 any other way of doing this?? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 13, 2014 Share Posted November 13, 2014 You can do it any way you want to do it. this code works fine when i replace the<div id="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"></div>;thing withecho "Whatever";it works fine then..Look at the difference. One of them is missing an echo statement and quotes. Link to comment Share on other sites More sharing options...
Junaid R Posted November 13, 2014 Author Share Posted November 13, 2014 man just suggest me what to read to learn some advanced php.. all the tutorials are too old and simple. and bro you were saying that echo and quotes are missing. you can also see that the statement which is without echo and qoutes does conatain a lot of quotes itself.. so they conflict with eachother Link to comment Share on other sites More sharing options...
justsomeguy Posted November 13, 2014 Share Posted November 13, 2014 you can also see that the statement which is without echo and qoutes does conatain a lot of quotes itself.. so they conflict with eachotherI know that, there are several ways you could solve that issue. Just leaving out the echo statement and the quotes is not one of the ways to solve it.if ($game == 'ballpool'){ echo '<div id="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"></div>';} if ($game == 'ballpool'){ echo "<div id="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"></div>";} if ($game == 'ballpool'){?><div id="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"></div><?php} if ($game == 'ballpool'){ echo <<<END<div id="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"></div>END;} http://php.net/manual/en/language.types.string.phpThere are plenty of books here if you want to learn:http://shop.oreilly.com/category/browse-subjects/programming/php.do?sortby=bestSellers&sortType=1 Link to comment Share on other sites More sharing options...
thescientist Posted November 13, 2014 Share Posted November 13, 2014 you can also see that the statement which is without echo and qoutes does conatain a lot of quotes itself.. so they conflict with eachother just because you have quotes _in_ it, does not mean it was syntactically correct. The entire string you were trying to generate needed be enclosed in quotes, just like the example you showed that worked. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now