Jump to content
xisto Community

WC2MyWorld

Members
  • Content Count

    1
  • Joined

  • Last visited

About WC2MyWorld

  • Rank
    Newbie

Profile Information

  • Gender
    Male
  • Location
    Australia
  • Interests
    Strange & unusual entities & events!
  1. Hi Everyone! Firstly, while I have experience with HTML/CSS and have dabbled a little in PHP/MySQL, I'm certainly not an expert! LOl! I have always written every page by hand and only used templates in CSS. I'm now attempting to use PHP/MySQL to store/retrieve HTML templates. I have been trying what seems a nice clear & simple method I found at one of the many respected online tutorial websites. As it is a website completely outside of this awesome community and I believe [rightly or wrongly - please correct if necessary] I cannot post the link here therefore I will have to try to explain the tutorial and then my issue. The tutorial explains the MySQL query to set up the table and then displays the following MySQL code: CREATE TABLE template (template_id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, Head_Open VARCHAR(60), Head_Close VARCHAR(60), Page_End VARCHAR(60), Date VARCHAR(60)); CREATE TABLE content (content_id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(60), body MEDIUMBLOB); Next the author explains and displays the MySQL query to add some data to the tables: INSERT INTO content (title, body) VALUES ( "MyPage", "This is my sample page, where I will use PHP and MySQL to template my website. <p> Here is a list of things I like <ul><li>PHP Code</li><li>MySQL</li><li><a href=http://php.about.com>PHP @ About.com</a></li></ul><p> That is the end of my content.") ; INSERT INTO template (Head_Open, Head_Close, Page_End, Date) VALUES ( "<html><head><title>", "</title><body>", "</body></html>", "$b = time (); print date('m/d/y',$ . '<br>';"); Next the tutorial explains and displays the following PHP code: <?php // Connects to your Database mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); mysql_select_db("Database_Name") or die(mysql_error()); //This retrieves the template and puts into an array. No WHERE clause is used, because we only have one template in our database. $coding = mysql_query("SELECT * FROM template") or die(mysql_error()); $template = mysql_fetch_array( $coding );//This retrieves the content and puts into an array. Notice we are calling ID 1, this would change if we wanted to call a page stored on a different row $text = mysql_query("SELECT * FROM content WHERE content_id =1") or die(mysql_error());$content = mysql_fetch_array( $text );//Actually puts the code and content on the page Print $template['Head_Open'];Print $content['title'];Print $template['Head_Close'];//When pulling PHP code we need to use EVAL Eval ($template['Date']);Print $content['body'];Print $template['Page_End']; ?> Obviously the script itself is rather well commented and simple to understand each line of code. The author does not, however, show or explain how to actually implement the PHP to display the result as a templated document/webpage. Perhaps the article was written for a more advanced user than myself ;p Can someone show me how to implement the PHP code please? I have entered the above PHP code into a file called 'template_001.php'. No matter how I try to call on this file the result is either a blank white page or the prompt to open/save/edit the php file. I'm using XAMPP 1.7.3 & Firefox. No changes to the XAMPP or Firefox installation are necessary as ONLY this script is not working. The problem is merely something I'm not doing right in the implementation of the script itself. I have tried using it as an 'include' & as a 'require', however, I still have no HTML displayed. The economics of this scripts usefulness is less important than understanding how to use it successfully. I would be most grateful if anyone could explain how to make this work. Cheers! Thankyou also to 'TrueFusion' for his reply as it prompted me to edit my question to clarify the outcome I need. Cheers!
×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.