Jump to content

Converting Website to PHP


SiriusB

Recommended Posts

Hi there.  Well first of all, hello *waves*

 

Right, down to business.

 

I currently have a small website here: http://smp.aeternum.co.uk

 

At the moment it is in XHTML and is static, apart from the contact page.

 

However, I have found since publishing the site that I make lots of changes every few days.  Normally this isn't a huge problem but occassionally I add extra pages/links and because of the way I have made the site, I have to update the code on each page.  While musing over the best way to manage my site I came up with a few things I would like to add, such as a comments feature for each page [or just the Troubleshooting page] and some other features.  So I thought I might as well change it over to PHP and stretch my new-found PHP skills.

 

No I come to do it, I find myself stuck as to the best way to approach it.

 

First of all I started with splitting the header, navigation and footer into their own .xhtml files and include them when necessary in one main smp.php file.  This stops repetition of code and also makes it easier to make changes.

 

The part I am stuck with is how to store and include the content.  I have considered a MySQL database, but I think I would lose all the XHTML formatting [paragraphs, headers, code etc] so instead thought of putting the content into their own .xhtml files for inclusion.  So now I have one .php file called smp.php which looks, roughly, like this:

 

include ('header.xhtml');

 

switch ($_GET['page'])

{

  case "Introduction":

      include ('introduction.xhtml');

      break;

 

  case etc etc

 

}

 

include ('navigation.xhtml');

include ('footer.xhtml');

 

Is this a good way of stucturing my site?  I have tested it, and it works but this current method has caused some new issues.

 

1:  I am not sure how to change to the keywords and description in the header.xhtml

2:  My CSS relies on an id added to the <body> element.  Again, I am not sure how to change this depending on the page.

 

Both of those items are in the header.xhtml file and are included [and displayed] before the content is chosen, so it is too late to change any of the details.

 

I know this section is just for Design and Layout but I thought I should highlight my current issues.  Is there a better way of dealing with this?

 

All help is greatly appreciated :)

Link to comment
Share on other sites

I have considered a database but MySQL can't store HTML [as far as I know] and the content of my site has all been marked up.  Again, my CSS relies on this.  Given the amount of content I think it would be poor practice to not mark up such a large amount of content - not least sections of text and code and headers.

 

Is there a way of storing HTML in MySQL?

Link to comment
Share on other sites

Ok, I wouldn't recommend using mysql for storing html, in my opinion you would be merging data and structure/design of your site.

Instead you have to analyze if you can structure your data (the varying content) and project it in a mysql table, for example:

If all your content have a title, a date, and a description, you could make a mysql table that have those fields:

 

table name -> dynamic_content

fields ->

id : an integer auto increment auto generated

title : varchar, an string field

date : datetime

content : blob

 

You will have to have then a cms (content management system), its not to hard to do for this cases since you just have to add, modify and delete the dynamic_contents you want.

 

 

 

Link to comment
Share on other sites

About the unique id in your body, I would do it this way:

My files tree:

- headers.php

- page1.php

- page2.php

- footer.php

 

in headers.php:

...
#The headers files goes from your doctype declaration to the closing head tag </head>
...
#if your variable keywords is not defined, you would just define it with a general keyword
<?php if(!isset($keywords)){ $keywords = "General keywords of you page"; } ?>
<meta name="KEYWORDS" content="<?php echo $keywords?>" />
...

 

in page1.php

...
#before you call your headers.php file you have to define your keywords variable:
$keywords = "Key words for my page";
include("headers.php");
#You will define the id inside the same file
<body id='page1'>
...

 

About the get parameter I wouldn't do it that way... you could just point your files as page1.php or page2.php, is just an opinion...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.