Basic Questions for Beginners in PHP

Source: Internet
Author: User
My younger brother to learn PHP, has always been to do ASP. PHP has a general understanding of the syntax, but also downloaded someone else's code template reference, I would like to ask you two questions
1. In 1, PHP code is mixed with HTML to write, can I ask you to write separately? HTML to HTML code, PHP code to PHP code so, two kinds of code to write together feel very messy and not conducive to maintenance AH

2.2 shows that there are two PHP code in the body, so when the page is loaded, it runs that piece of code? Or are they running in two sections? Which section to run first? If there are two buttons on the same page to implement different functions, then how to implement Click Button 1 to execute a piece of PHP code (for example, method a)? Click button 2 to execute a PHP code (for example, Method B)?
I hope you will help the experts to answer the next

Figure 1:


Figure 2:


Reply to discussion (solution)

1. Can I separate the code from ASP. I just know that C # implements code separation with accompanying files
PHP needs to introduce a template engine class to implement code separation

2, you do not have the basis of programming, is not the code to be separated by conditional statements do not see it?
Now that the code is in the conditional branch, it's natural to have conditional execution.

Using a framework such as thinkphp, or a template such as: Smarty can be implemented in PHP and HTML separation
PHP files are executed from the top down order.

Search PHP MVC
View is separated from logic and data!

1. Can I separate the code from ASP. I just know that C # implements code separation with accompanying files
PHP needs to introduce a template engine class to implement code separation

2, you do not have the basis of programming, is not the code to be separated by conditional statements do not see it?
Now that the code is in the conditional branch, it's natural to have conditional execution.



That code is conditional branching, if the code is written like this:
echo "A";
?>
echo "B";
?>
In this case, is output a, or a A, A/b output? Output when the page is loaded? If I want to only run the first PHP code when the page loads (just output a) is that okay?

If you don't want to output it, put it in the conditional no branch, or comment out
I'm kind of wondering if you really did ASP.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.