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? 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 {
?>


Reply to discussion (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.

First, php is in service? ? While html is in ?? ?. Php? Better than html? Line.


Because? Medium? Not the php generation ?, So we need to score ??? Php ???
If you need to combine? A whole segment is php, medium? You need to use php echo ??.

For example

 '; Echo''; Echo'No book information!'; Echo''; Echo''; Echo'
 
 
  
  
'; Echo'
  
  
     '; Echo' 
    '; Echo' 
   '; Echo' 
  
'; Echo' add the Library Information
';} Else {}?>

Html + php mixed encoding mode

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

I use SQL server2005. how can I change the query function (in red) to the sqlsrv function?

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.