Jump to content


Photo

php and css


  • Please log in to reply
2 replies to this topic

#1 jagguy

jagguy
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts

Posted 24 October 2006 - 11:09 AM

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?

#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 24 October 2006 - 03:37 PM

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 (www.cakephp.org)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 http://www.w3schools...s/css_intro.asp

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

#3 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 24 October 2006 - 03:45 PM

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....mplate_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.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users