-
February 26th, 2003, 07:27 PM
#1
Junior Member
Help me please
I need help with some code I'm new to PHP so don't get too harsh.
Heres all the code I've separated it into separate files though
index.php
<?
$title="PHP Index";
$menu=include_once("php/menu.php");
$body=include_once("php/body.php");
include_once "php/templates/complexTemplate.php";
?>
php/menu.php
<?
print("Menu");
?>
php/body.php
<?
print("body")
?>
<?
print <<<END
<HTML>
<HEAD>
<TITLE>$title</TITLE>
</HEAD>
<BODY>
<TABLE width=100%>
<TR>
<TD width=30%>
$menu
</TD>
<TD>
$body
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
END;
?>
and this is the output.
Menubody
1 1
why isn't the "Menu" and the "body" separated and what is up with the two 1's
thanks for any help
-
February 27th, 2003, 11:53 AM
#2
Ok, it toke me a while to get through your post, but let me make this clear. You have 3 files, which contain the following:
index.php
PHP Code:
<?
$title="PHP Index";
$menu=include_once("php/menu.php");
$body=include_once("php/body.php");
include_once "php/templates/complexTemplate.php";
?>
php/menu.php
PHP Code:
<?
print("Menu");
?>
php/body.php
PHP Code:
<?
print("body");
?>
<?
print <<<END
<HTML>
<HEAD>
<TITLE>$title</TITLE>
</HEAD>
<BODY>
<TABLE width=100%>
<TR>
<TD width=30%>
$menu
</TD>
<TD>
$body
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
END;
?>
Ok, there is A LOT wrong with this script, but I'll get to that later. :-) First, i'll answer your questions.
The "Menu" and "body" aren't seperated because you didn't told PHP to seperate them. First, you include menu.php, which on its turn, prints the string "Menu". Then, you include body.php, which first prints the string "body", and then some other stuff. Note: You have NO spaces between the print("Menu") and print("body") command. So, untill now, we've only printed a total of "Menubody" to the user.
Ok, then you output some html tags, and then the following line:
$menu
and then after some more html another line
$body
You have specified those variables with an include() command in inde.php earlier. The "function" unclude() DOES NOT return the content of the file to the variable, as you are trying to do here. It only returns if it succesfully included the file, as in TRUE or FALSE. So, in your case, both files were included, so you get 2 one's.
Some hints:
1. Stick with normal <?php ?> tags instead of <? ?> They aren't supported at every server.
2. Always insert those nice ;'s, also when people say that it aint nescesary. It just keeps your code neat, and compatible with different servers.
3. This aint really a hint, but I never user those <<<<<<<<<< code crap. I always keep things neat by just using, in this case, print("some text") or include("thisfile.php"). I just think its much easier to look at when you later want to look something up in your code.
4. Go to www.PHP.net, and do some tuts, read the manual etc.
5. Go to www.w3schools.com and look up some tuts on html.
Hope this helped.
-
February 27th, 2003, 12:09 PM
#3
The other thing is.. you can use the following:
PHP Code:
<?php
echo "Menu ";
?>
...
<?php
echo " Body";
?>
You need to put in the space. When you display text, think along the lines of HTML. The echo command works great for putting up HTML within your PHP.
You migth also want to check out -- in addition to the sites Sick Dwarf suggested -- PHPBuilder and PHPFreaks. Both aren't bad.
-
February 28th, 2003, 05:32 PM
#4
Junior Member
Thanks for your guy's help. I was just trying to see if include() would take in the file as a string and asign it to the set variables then when the template would be loaded it would plug in those strings for the body and menu to try to make things look neater.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|