Jump to content

Archived

This topic is now archived and is closed to further replies.

jagguy

php and css

Recommended Posts

If i want to display data with php from mysql. Also on the webpage I want a left and top menu and it requires some css/html.
Having css,php and html all in the 1 webpage can look messy. I can do it by including the php script where it is requires in a div tag.

Is there any easier or standard way to have 3 different code types  on the 1 webpage?

Share this post


Link to post
Share on other sites
The Model/View/controller (MVC) approach is pretty much a standard, although sometimes complex to implement. It basically means that you separate your content from your logic from your presentation. There are frameworks out there which will allow you to follow this approach, and it might be worth your while to have a look at what's out there. I have used CakePHP ([url=http://www.cakephp.org]www.cakephp.org[/url])and have found that to be sufficient for my needs, although it was quite a steep learning curve.

Having said that, IMHO it is fine to have PHP and HTML in the same file as long as you try your best to make it readable, standards based, and use semantic markup. Also, try to do all the logic in one place, and then echo the result in the relevant HTML.

For CSS, I would definitely stress that you use external stylesheets which can be linked to from within that file.

For CSS, have a look at [url=http://www.w3schools.com/css/css_intro.asp]http://www.w3schools.com/css/css_intro.asp[/url]

There are probably many schools of thought on this topic, but that's my 2p worth!

Share this post


Link to post
Share on other sites
yeah - if mess is a prime concern, then something along the MVC road is gonna help tonnes. I personally like CodeIgniter (www.codeigniter.com) as it's pretty lightweight and only includes what you use. If you're after something a little more simple, then try templating using a template engine. Smarty seems to be the most popular, but I find it trickier to use than many.  there's a simple one here, with an explaination of why i didn't choose smarty: http://www.massassi.com/php/articles/template_engines/ and another recommendation is here: http://phpsavant.com/yawiki/

Whichever you choose, the end result is seperation of your business logic from your presentation - leaving a set of nice clean HTML documents and a set of nice PHP scripts.

Share this post


Link to post
Share on other sites

×

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.