Page 1 of 1

[SOLVED]if and echo

Posted: Mon Jan 09, 2006 2:12 pm
by nickman013
I am trying to make a script that if someone goes to the url...

http://www.example.com/play.php?page=video1

it will echo that script.

this is what ive got so far...

Code: Select all

<?
if ($page=="gotti1") 
{
echo "<html>
<title>The Gotti Adventure</title>
<center>
<BODY BGCOLOR=#808080>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=5>
The Gotti Adventure
</font><br>
<font color=white size=2>
Stealing Johns Glove
</font>
</td></table>
<p>
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222>
<font color=white><b>CHECK OUT THE <a href=http://www.regionalplanning.com/nvideos/GottiVideoMain2.php3?gottisn=<? echo $gottisn; ?>>GOTTI VIDEO 2!!</a></b></font>
</td></table><p>
<p>
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222>
<embed src=GottiAdventure.mp4 width=358 height=320 controller=true autoplay=true loop=false></embed></table>
</font></td>
</table>
</body>
</center>
</html>";
}
if ($page=="gotti2") 
{
echo "
<center>
<BODY BGCOLOR=#808080>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=5>
The Gotti Adventure
</font><br>
<font color=white size=2>
Monkey
</font>
</td></table>
<p>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<embed src=GottiAdventure2_mov.mov width=490 height=380 controller=true autoplay=true loop=false></embed></table>
<p>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=2>
<img src=wm.gif>Windows Media Player users click <a href=GottiAdventure2_mov.wmv>here</a>.
</font>
</td></table>
<p>";
}
?>
i am using php 4 (finally upgraded =] )

also if there is no page in the url i want it to be a regular page... so i guess that would be else.

Posted: Mon Jan 09, 2006 2:19 pm
by hawleyjr
Break up your PHP and HTML

Code: Select all

<?php
if ($page=="gotti1") 
{
?>
<html>
<title>The Gotti Adventure</title>
<center>
<BODY BGCOLOR=#808080>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=5>
The Gotti Adventure
</font><br>
<font color=white size=2>
Stealing Johns Glove
</font>
</td></table>
<p>
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222>
<font color=white><b>CHECK OUT THE <a href=http://www.regionalplanning.com/nvideos/GottiVideoMain2.php3?gottisn=<? echo $gottisn; ?>>GOTTI VIDEO 2!!</a></b></font>
</td></table><p>
<p>
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222>
<embed src=GottiAdventure.mp4 width=358 height=320 controller=true autoplay=true loop=false></embed></table>
</font></td>
</table>
</body>
</center>
</html>
<?php
}
if ($page=="gotti2") 
{
?>
<center>
<BODY BGCOLOR=#808080>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=5>
The Gotti Adventure
</font><br>
<font color=white size=2>
Monkey
</font>
</td></table>
<p>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<embed src=GottiAdventure2_mov.mov width=490 height=380 controller=true autoplay=true loop=false></embed></table>
<p>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=2>
<img src=wm.gif>Windows Media Player users click <a href=GottiAdventure2_mov.wmv>here</a>.
</font>
</td></table>
<p>
<?php
}
?>

Posted: Mon Jan 09, 2006 2:22 pm
by matthijs
I think this article at digital web explains exactly what you want:
http://www.digital-web.com/articles/easypeasy_php_2/
It goes like this:

Code: Select all

// Include our header:
		include($_SERVER['DOCUMENT_ROOT'] . '/inc/header.php');
		
	// Define our array of allowed $_GET values
		$pass = array('intro','bluetruck','redhouse','brownbear');
			
	// If the page is allowed, include it:
		if (in_array($_GET['id'], $pass)) {
			include ($_SERVER['DOCUMENT_ROOT'] . '/inc/' . $_GET['id'] . '.php'); 
		} 
		
	// If there is no $_GET['id'] defined, then serve the homepage:
		elseif (!isset($_GET['id'])) {
			include ($_SERVER['DOCUMENT_ROOT'] . '/inc/intro.php'); 
		}
But check out the article and downloadable files to see the details.

Posted: Mon Jan 09, 2006 2:29 pm
by nickman013
hawleyjr wrote:Break up your PHP and HTML

Code: Select all

<?php
if ($page=="gotti1") 
{
?>
<html>
<title>The Gotti Adventure</title>
<center>
<BODY BGCOLOR=#808080>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=5>
The Gotti Adventure
</font><br>
<font color=white size=2>
Stealing Johns Glove
</font>
</td></table>
<p>
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222>
<font color=white><b>CHECK OUT THE <a href=http://www.regionalplanning.com/nvideos/GottiVideoMain2.php3?gottisn=<? echo $gottisn; ?>>GOTTI VIDEO 2!!</a></b></font>
</td></table><p>
<p>
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222>
<embed src=GottiAdventure.mp4 width=358 height=320 controller=true autoplay=true loop=false></embed></table>
</font></td>
</table>
</body>
</center>
</html>
<?php
}
if ($page=="gotti2") 
{
?>
<center>
<BODY BGCOLOR=#808080>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=5>
The Gotti Adventure
</font><br>
<font color=white size=2>
Monkey
</font>
</td></table>
<p>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<embed src=GottiAdventure2_mov.mov width=490 height=380 controller=true autoplay=true loop=false></embed></table>
<p>
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222>
<center><font color=white size=2>
<img src=wm.gif>Windows Media Player users click <a href=GottiAdventure2_mov.wmv>here</a>.
</font>
</td></table>
<p>
<?php
}
?>
thank you both, i tried the script above and it worked just how i wanted it, thanks alot both of you!

Posted: Mon Jan 09, 2006 2:36 pm
by nickman013
actually i have one more thing

if there is no page inputted i want a different html code to be activated

my script so far is

Code: Select all

<html><title>Video Page</title>
<?php 
if ($page=="gotti1") 
{ 
?> 
<html> 
<title>The Gotti Adventure</title> 
<center> 
<BODY BGCOLOR=#808080> 
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222> 
<center><font color=white size=5> 
The Gotti Adventure 
</font><br> 
<font color=white size=2> 
Stealing Johns Glove 
</font> 
</td></table> 
<p> 
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222> 
<font color=white><b>CHECK OUT THE <a href=http://www.regionalplanning.com/nvideos/GottiVideoMain2.php3?gottisn=<? echo $gottisn; ?>>GOTTI VIDEO 2!!</a></b></font> 
</td></table><p> 
<p> 
<TABLE BORDER="0" bgcolor=#000000><td bgcolor=#B22222> 
<embed src=GottiAdventure.mp4 width=358 height=320 controller=true autoplay=true loop=false></embed></table> 
</font></td> 
</table> 
</body> 
</center> 
</html> 
<?php 
} 
if ($page=="gotti2") 
{ 
?> 
<center> 
<BODY BGCOLOR=#808080> 
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222> 
<center><font color=white size=5> 
The Gotti Adventure 
</font><br> 
<font color=white size=2> 
Monkey 
</font> 
</td></table> 
<p> 
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222> 
<embed src=GottiAdventure2_mov.mov width=490 height=380 controller=true autoplay=true loop=false></embed></table> 
<p> 
<TABLE BORDER=0 bgcolor=#000000><td bgcolor=#B22222> 
<center><font color=white size=2> 
<img src=wm.gif>Windows Media Player users click <a href=GottiAdventure2_mov.wmv>here</a>. 
</font> 
</td></table> 
<p> 
<?php 
} 
else {
echo "video page main html";
}
it works but when a page is inputted the other page html is on the bottom of it...

Posted: Mon Jan 09, 2006 2:44 pm
by hawleyjr
You need to combine All of your if statements into and if else statement.

Posted: Mon Jan 09, 2006 6:40 pm
by nickman013
how do i do that? is there a link or somthing you can show me..

thanks!

Posted: Mon Jan 09, 2006 6:43 pm
by hawleyjr
You have two seperate if statements

Code: Select all

<?php
if ($page=="gotti1")
{
?>
and

Code: Select all

<?php
}
if ($page=="gotti2")
{
?>
Add an else statement before the second if.

Code: Select all

<?php
}elseif ($page=="gotti2")
{
?>

Posted: Mon Jan 09, 2006 8:31 pm
by nickman013
thanks so much it works perfect!!!