Page 1 of 1

Inserting PHP code into existing PHP

Posted: Mon Jun 17, 2002 10:19 am
by Bennettman
I'm working on a fanfic script, viewable at http://tisoft.subfactor.net/remote/fanfic.php. Currently the bottom fic (Story 1) is what I have working. The problem is, I want to make it so that (to avoid having to paste the same PHP code for every fic) the main part of the code (in fanfic_code.php) is inserted into the existing PHP code. However, when I try the include tag, it actually writes the code to the screen, creating the top story in the page. And since I'm a newbie to PHP, I don't know any command to put the code in. Anyone?


fanfic.php code
<?php

$name = ("The Pendant");
$fic = ("thependant");
$totalpage = 13;
$author = ("<a href=mailto:juneaskew@hotmail.com>Sique</a>");
$genre = ("Action/Adventure/Drama");
$description = ("Around the happenings of Sique. A new member has joined Vyse's crew. But there is something about the pendant she has.");

$link = 1;

Code to add the contents of fanfic_code.php

?>


fanfic_code.php contents
print ("<tr><td rowspan=3 bgcolor=#E3E7E3 width=40 align=center><img src=http://dynamic3.gamespy.com/~soaworld/i ... on.gif><td colspan=3 bgcolor=#E3E7E3>&nbsp;");
print ("<a href=story.php?fic=");
print ("$fic");
print (";page=1;totalpage=");
print ("$totalpage");
print (">");
print ("$name");
print ("</a></td></tr><tr><td bgcolor=#E3E7E3>&nbsp;Author:&nbsp;");
print ("$author");
print ("</td><td bgcolor=#E3E7E3>&nbsp;Genre:&nbsp;");
print ("$genre");
print ("</td><td bgcolor=#E3E7E3>&nbsp;Pages:&nbsp;");
while ($link <= $totalpage) {
print ("<a href=story.php?fic=");
print ("$fic");
print (";page=");
print ("$link");
print (";totalpage=");
print ("$totalpage");
print (">");
print ("$link");
print ("</a>&nbsp;");
$link = $link + 1;
}
print ("</td></tr><tr><td colspan=3 bgcolor=#E3E7E3>&nbsp;Description:&nbsp;");
print ("$description");
print ("</td></tr>");

Posted: Mon Jun 17, 2002 10:50 am
by Bennettman
Hmmmmmmmmmm... that's the second time I've posted my problem, then worked it out myself ;p

Posted: Tue Jun 18, 2002 3:31 am
by twigletmac
Unsolicited but... If you want to take some of the effort out of typing your code by getting rid of all those parenthesis and a lot of quotes:

Code: Select all

fanfic.php code 
<?php 
$name = 'The Pendant'; 
$fic = 'thependant'; 
$totalpage = 13; 
$author = '<a href="mailto:juneaskew@hotmail.com">Sique</a>'; 
$genre = 'Action/Adventure/Drama'; 
$description = 'Around the happenings of Sique. A new member has joined Vyse's crew. But there is something about the pendant she has.';

$link = 1; 

Code to add the contents of fanfic_code.php 

?>
fanfic_code.php contents

Code: Select all

<?php
echo <<<END
<tr>
	<td rowspan="3" bgcolor="#E3E7E3" width="40" align="center">
		<img src="http://dynamic3.gamespy.com/~soaworld/iB_html/non-cgi/Skin/Default/images/on.gif" />
	</td>
	<td colspan="3" bgcolor="#E3E7E3">
		<a href="story.php?fic=$fic;page=1;totalpage=$totalpage">$name</a>
	</td>
</tr>
<tr>
	<td bgcolor="#E3E7E3">Author: $author</td>
	<td bgcolor="#E3E7E3">Genre: $genre</td>
	<td bgcolor="#E3E7E3">Pages:
END;
for ($link = 1; $link <= $totalpage; $link++) &#123; 
	echo <<<END
		<a href="story.php?fic=$fic;page=$link;totalpage=$totalpage">$link</a>&nbsp;
END;
&#125;
	echo <<<END
	</td>
</tr>
<tr>
	<td colspan="3" bgcolor="#E3E7E3">Description: $description</td>
</tr>
END;
?>
Mac