Why do I need to write a complete php code separately?

Source: Internet
Author: User
Why do I need to write a complete php code separately? At last, this post was edited by u014060468 from 2014-06-2009:53:43. for details, see the code. why do I need to write a complete php code separately? What if I write together? & Lt ;? Phpinclude (Connconn. php); $ querymysq why is a complete php code sometimes written separately?

This post was last edited by u014060468 at 09:53:43

Seeing the code, I don't understand why I want to write a complete php code separately? What if I write together?
Include ("Conn/conn. php ");
$ Query = mysql_query ("select book. barcode, book. id as bookid, book. bookname, bt. typename, pb. pubname, bc. name from tb_bookinfo book join tb_booktype bt on book. typeid = bt. id join tb_publishing pb on book. ISBN = pb. ISBN join tb_bookcase bc on book. bookcase = bc. id ");
$ Result = mysql_fetch_array ($ query );
If ($ result = false ){
?>




No book information!






Add book information

} Else {
?>

------ Solution --------------------
The Black part is html code, not php code.
You can say that html is embedded in php, or php is embedded in html.
The advantage of this writing method is that you can use visual html tools (such as DW) to observe and modify the html part.

In combination, the html part should be placed in the string. Because a single double quotation mark exists at the same time, escaping reduces visibility.
If custom delimiters are used, the code will be less elegant due to the rule.
You can also put it in a separate file and include it in. However, leaving the visual space will affect the continuity of thinking.
------ Solution --------------------
First, php is implemented in the server, while html is implemented in the server. Php will run better than html.


Because the middle stage is not the php generation, we need to split two php versions to compile
If you need to combine the entire part of php, you need to use php echo to compile the html.

For example


Include ("Conn/conn. php ");
$ Query = mysql_query ("select book. barcode, book. id as bookid, book. bookname, bt. typename, pb. pubname, bc. name from tb_bookinfo book join tb_booktype bt on book. typeid = bt. id join tb_publishing pb on book. ISBN = pb. ISBN join tb_bookcase bc on book. bookcase = bc. id ");
$ Result = mysql_fetch_array ($ query );
If ($ result = false ){
Echo'



';Echo' ';Echo' ';Echo' ';Echo'
No book information!
';
Echo'



';Echo' ';Echo' ';Echo' ';Echo'
';
Echo 'add book information
';
} Else {

}
?>

------ Solution --------------------
Html + php mixed encoding mode

The template smarty can be used to separate php and html for easy maintenance.

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.