html - include PHP code inside another PHP page that is created using PHP? -
i understand title bit confusing couldn't find better way title question!
i try best explain here:
i creating page extension of .php using php file. works fine. php file has html codes in it. .php file .html codes. works fine too.
now, trying put php code @ top of created php file can connect mysql database.
but when place php code connecting database @ top of page, , when page created, create blank page! , when view page source in browser, there not single html code in page!
i hope haven't confused guys far...
this code creates blank page:
$i=1; while($file = fopen("untitled$i.php", "r")) { fclose($file); $i++; } if($file = fopen("untitled$i.php", "w")) { $html ='<?php include "config/connect.php"; $dynamiclist = ""; $sql = "select distinct filename pages"; $query = mysqli_query($db_conx, $sql); $productcount = mysqli_num_rows($query); // count output amount if ($productcount > 0) { while($row = mysqli_fetch_array($query, mysqli_assoc)){ $category = $row["category"]; $dynamiclist .= "<li><a href="#">' . $filename . '</a></li>"; } } ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-us"> <head profile="http://gmpg.org/xfn/11"> **rest of html code goes here.....................**
this code creates page should , works fine:
$i=1; while($file = fopen("untitled$i.php", "r")) { fclose($file); $i++; } if($file = fopen("untitled$i.php", "w")) { $html =' <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-us"> <head profile="http://gmpg.org/xfn/11"> **rest of html code goes here.....................**
what doing wrong?
you cant pass php tags , variables string. reason not see because browser not understand passed before
what trying bad practice overall. sure there not other way creating n of php files?
-- alright see comment ill try explain how php works
lets have www.website.com , here have basic main page , menu
menu contains following : cars, mobiles, tablets
using desing create www.website.com/cars.php, mobiles.php, tablets.php - that's wrong, youre trashing programming language has offer.
instead of should use url variables >
www.website.com/index.php?page=cars www.website.com/index.php?page=mobiles ...
now in php code check if page set , value
if(isset($_get['page'])){ if($_get['page'] == 'cars'){ // cars page mysql_query("select * cars color = 'blue'"); } else if($_get['page'] == 'mobiles'){ // mobile page mysql_query("select * mobiles os = 'android'"); } } else{ // main page }
this how handle php.
i stronly suggest read http://www.w3schools.com/php/ - before go further.
Comments
Post a Comment