specifically, PHP's job is to write HTML. Yeah, there's lots of cool stuff it can do on the way there, and the possibilities go far beyond includes, mysql, and mail. but the end goal is to write a webpage. keeping this in mind will be very, very, very helpful as you learn.
you do not have a webpage that you insert php code into: you have php code that gives you a webpage when it's done running. As soon as you use php, the entire page is a php script - the plain html parts are just stuff you don't do anything to before your script outputs it.
If there was one thing I would change about how I learned php, that would be it. my advice is to separate your php from your html as much as possible. Do all your database calls and processing first. use $variables to save your html markup instead of echoing everything as you build it. Your aim should be to output no html - nothing at all - until the very end of your php script. doing so will also allow you to get into higher level functions later on without having to completely re-learn how to code.
an example:
instead of doing this -
PHP Code:
// [...]
$result = mysql_query("SELECT * FROM `table`");
while($row = mysql_fetch_array($result)){
echo 'Row 1 value: ';
echo $row[0];
echo '<br>';
// etc., etc.
}
do this -
PHP Code:
// [...]
$result = mysql_query("SELECT * FROM `table`");
$info = ''; // you're going to put all your markup here
while($row = mysql_fetch_array($result)){
$info .= 'Row 1 value: ';
$info .= $row[0];
$info .= '<br>';
}
echo $info;
have fun!
Bookmarks