Hi,
I've been teaching myself php out of necessity for a web project at work and I've run into a situation in which I currently have three different php pages that are used to display three different data grids. However, most of the code is the same, aside from the javascript grids themselves (in terms of size, number of columns, data content, etc.) and the tables that the grids live in. So, the only unique portions of each page are the tables and the grids (which live in one of the table cells). Aside from that, the pages are identical in terms of the php functions used. So what I'd like to do is have a single page that sources in the appropriate table and grid data depending on which environment is selected from the parent page. I was thinking about creating three separate include files in which the appropriate table and grid data could be included into the single page and then displayed depending on the environment. But given that php is very new to me, I thought I'd get some advice from people who are a lot more familiar with php than I am.
Is my approach reasonable or should I be doing something else entirely?
The idea here is that I'd like to use a single php page for all of my common elements and then source in the data that's unique to each page.

Thanks,
Steve

Member Avatar for diafol

one include file with a function for outputting certain data in a certain format:

in your include file:

function getOutput($input,$format){
  ...
  return $grid;
}

to display:

echo getOutput(...,...);

Code should have as little duplication as possible. OOP is great for this, but as you're starting out, it may be a bit extreme. Putting reusable code into functions helps.

Perfect. Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.