10 replies [Last post]
Phreestyle
Phreestyle's picture
Offline
Enthusiast
Australia
Last seen: 6 years 37 weeks ago
Australia
Timezone: GMT+8
Joined: 2007-05-12
Posts: 235
Points: 6

hi everyone.
Long time no ask.

So, my question is this. Do you think it is better (ie, what is your preference?)to place html within php functions or have a number of seperate php files and place them within html tags?

For example:
option one

 include "one giant php file with markup";

or

option two

<ul>
<li><?php include "php file one"?></li>
<li><?php include "php file two"?></li>
<li><?php include "php file three"?></li>
</ul>

I tend to prefer the second option, but I end up with a lot of small php files, which can end up as a major management hassle. I would appreciate any input you can give.

cheers,
Rob

code tags added!

Life's a journey. Enjoy the trip.

Tags:
Phreestyle
Phreestyle's picture
Offline
Enthusiast
Australia
Last seen: 6 years 37 weeks ago
Australia
Timezone: GMT+8
Joined: 2007-05-12
Posts: 235
Points: 6

Sorry, I didn't use code tags

Sorry, I didn't use code tags and I can't figure out how to edit my post. If a mod could sort that out it would be great, or indicate how I edit the post.
regards,
rob

Life's a journey. Enjoy the trip.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

This is a sort of question

This is a sort of question that all depends on...

Generally the master page/file might have say three major includes a head or top section perhaps nav/menu include, a footer include.

There might be any number of further includes within other includes who knows.

I don't think there is one clear answer to your question really and depends on quite what you are trying to do.

btw should have posted this to 'Off topic' moving !

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Now I have added code tags I

Now I have added code tags I have to question what you're doing, no each LI is not a separate file you can't manage things that way the ul is one include file within the ul include do what ever scripting needed.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Phreestyle
Phreestyle's picture
Offline
Enthusiast
Australia
Last seen: 6 years 37 weeks ago
Australia
Timezone: GMT+8
Joined: 2007-05-12
Posts: 235
Points: 6

Thanks for your response

Thanks for your response Hugo. Sorry, I wasn't really very clear.

I was building a user input form with data populating a number of option lists - ie, option lists for year, month, sales figures and sales rep.

The data that populates the list comes from a number of sql queries. I was wondering if I should consolidate all the queries into one giant php file and then add that in to my page, or have the queries into separate files and include them in the final page as includes within li tags.

If I understand you correctly, you recommend parsing the php in total and then include the final result en-mass.

Thanks for your input.

Life's a journey. Enjoy the trip.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Sounds to me that you are

Sounds to me that you are essentially querying one table for a array of data, isn't it easier to do in one file and then output your UL below it with LI elements populated from the array?

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 10 years 1 week ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

For me, I try to do

For me, I try to do everything that isn't html output before the html output. E.g., do all three queries in one place and put the results you want to display into an three variables (populated arrays if the result set is small, or result set resources if they could be large). Then include your output template HTML with php tags that iterate over the array/result set.

The choice of how to break things into files should be governed by not repeating the same stuff in two different files. After that any choice to split things further is personal choice depending on how you prefer your site/files organized. I dislike large monolithic files so break things up.

The two key principles are DRY and KISS. Keep those in your mind at all times and you won't go wrong.

Phreestyle
Phreestyle's picture
Offline
Enthusiast
Australia
Last seen: 6 years 37 weeks ago
Australia
Timezone: GMT+8
Joined: 2007-05-12
Posts: 235
Points: 6

Thanks Chris and Hugo. Thank

Thanks Chris and Hugo. Thank you both for your input.

My inclination is to try to separate the backend stuff from the markup if and where I can. I generally find it difficult to backtrack and find html markup that is buried deep within a php function. Especially if it is some months later or a collaborative project.

I was just wondering what others do. The stuff I read on the net seems to treat the html as a necessary evil required to display the output of the php code, and doesn't really seem to have a semantic basis. As an example, the use of the <br /> tag seems to be endemic.

thanks again for your input
regards
rob

Life's a journey. Enjoy the trip.

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 10 years 1 week ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Phreestyle wrote: As an

Phreestyle wrote:

As an example, the use of the <br /> tag seems to be endemic.

That's code monkeys for you. Templates should be written by people who understand html and css. I work with people who (if I didn't harangue them) would be happy to stick everything in divs.

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 7 years 37 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

I'm afraid backend scripters

I'm afraid backend scripters are holding sway over matters at the moment and they are NOT the best people to be dealing with the view aspect of dynamic templated sites. I have said this before but I'm constantly surprised by the attitude of scripters who think the job is done when they have obscufated and abstracted their scripting to the nth degree and shrug when it comes to actually outputing browser markup and throw out any old rubbish and I'm not exaggerating.

Like Chris has expressed templates should be written by those who have the frontend skills.

Why my rant? having to work with WP WPMU and BuddyPress and fighting bad code all the way.

Chris can probably express this better than I but yes you must separate scripting from markup as much as possible and where not possible keep it very regimented and uniform don't simply chuck markup into functions dotted all over the place because it's easier or perhaps it is then write all functions to one file that can be included and functions referenced where needed.

1000 ways to skin a cat, PHP has no real form and I guess templating frameworks such as Cake or codeIgnitor or are perhaps one solution?

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Phreestyle
Phreestyle's picture
Offline
Enthusiast
Australia
Last seen: 6 years 37 weeks ago
Australia
Timezone: GMT+8
Joined: 2007-05-12
Posts: 235
Points: 6

I'm hearing you loud and

I'm hearing you loud and clear.

I've just finished a Joomla/Virtuemart shopping cart for a client, and what an absolute nightmare. CSS files scattered across three different directories and, as if that wasn't bad enough, in line css hard coded in multiple php and javascript files. Finding where the style rule was coming from, ate up days and days of my time.

In addition, ID and Classes - if there were any at all - had names like "div1" or "user3". Aaah, I can feel my blood pressure rising just thinking about it.

What appeared to be a cheap option for the client ended up costing them both time and money. I guess these 'free' solutions are only free if you don't put a value on time.

cheers,

Life's a journey. Enjoy the trip.