HarrySeah Posted September 18, 2016 Share Posted September 18, 2016 Hi i am new for the PHP, i had the experienced before to do a login system page but what i want it is HTML and PHP file to separate i dont want PHP with HTML together to 1 file , cause professional people will more likely to use 2 file rather than 1 file easy to maintain and edit how to use the external PHP file coding without re-design whole page cause normally what i tested before was link or turn to other new page and result will come out but the design was totally gone so have any ways and suggestion to do that ... in the end, im sorry i not well in english and my knowledge of PHP still quite new , thanks you so much Link to comment Share on other sites More sharing options...
dsonesuk Posted September 18, 2016 Share Posted September 18, 2016 You can't separate one from the other, the end result is to return from server, php code as html into a page which is inserted into a template at a specific location using php include. A template page usually consists of head (<head>...</head>) content, nav content, main content area, and footer content. Any of these could use php to gather content from mysql database for specific page. Link to comment Share on other sites More sharing options...
HarrySeah Posted September 19, 2016 Author Share Posted September 19, 2016 To: dsonesuk Thank you so much for reply and the answer too That mean, PHP page in the end also need to insert the HTML content like nav bar ,footer all that (copy from the previous page design code) Okok,i get it , but what i saw other people of PHP code , they dont have any html content , just start as <?php ...?> so how they work and connected all the code,cause if dont have any html content for design when running the page , the result will show it but the design will gone all .... no way to maintain the design or page and run other php page ... isnt ajax will work like that ? im sorry for my english not well...hope you understand what i mean ... Thanks for helping , once again Link to comment Share on other sites More sharing options...
dsonesuk Posted September 19, 2016 Share Posted September 19, 2016 Yes! you can make whole of html code within a php page echo/print out as a php text string, if you want to go that way. <?php echo '<!DOCTYPE html>'."\n" echo '<html>'."\n" echo '<head>'."\n" echo '</head>'."\n" echo '<body>'."\n" echo '<div id="test"></div>'."\n" echo '<input type="button" value="Change">'."\n" echo '</body>'."\n" echo '</html>'."\n" OR <?php echo <<<EOT </head> <body> <div id="test"></div> <input type="button"value="Change"> </body> </html> EOT; AJAX runs AFTER a page is returned from server as html and fully rendered and is triggered by a specific event captured by JavaScript. it uses JavaScript to send a request for data from php file which is returned as html to be inserted to specific location (usually by a id ref of specific element) without the need to reload the page again. IT should be added as a improved method over a totally php method which causes a reload of a page, as JavaScript is required to be enabled for the AJAX method to work. Link to comment Share on other sites More sharing options...
HarrySeah Posted September 19, 2016 Author Share Posted September 19, 2016 To: dsonesuk Thank you so much Thanks for given me the example and explanation Thanks for helping i will try next time but what i seen people php page before was whole php code and not embed any html code and especially not write it on echo to print out just like declare a variable and assign the value too ,if not mistaken so how to run it ... if run it ... how to connect and the page may re-design again @@ ahaha thanks again Link to comment Share on other sites More sharing options...
dsonesuk Posted September 19, 2016 Share Posted September 19, 2016 <?php $head ='<!DOCTYPE html>'."\n"; $head.= '<html>'."\n"; $head.= '<head>'."\n"; $head.= '</head>'."\n"; $body = '<body>'."\n"; $body.= '<div id="test"></div>'."\n"; $body.= '<input type="button" value="Change">'."\n"; $body.= '</body>'."\n"; $html_close ='</html>'."\n"; echo $head.$body.$html_close; But you could divide 1st post#4 example into two or three separate php files (head.php, content.php, footer.php) Then include them in a php template file using <php include 'head.php'; include 'content.php'; include 'footer.php'; This will gather php generated html text string and include contents in the php template page. Link to comment Share on other sites More sharing options...
HarrySeah Posted September 21, 2016 Author Share Posted September 21, 2016 To: dsonesuk Thanks again for you reply and helping Thanks to sharing me different idea and concept of the code I will try next time, and sharing which the best way to solve that thank you so much once again Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now