Reusable PHP file with different MySQL tables

Viewed 40

I was curious if someone could point me in the right direction.

I am going to be using the same index.php file over and over and I didn't know if there is an easier way to update it with each new MySQL tables that I create. Was trying to save time and not have to search for every piece of code to change every time I reuse the index.php file.

I have the layout and design I want to reuse. Just need to update the php file to the new table.

I didn't know if this would use variables to do this or not.

If someone could just point me what to research or lookup I would appreciate it. I want to learn and don't mind doing the work.

Basically it would be as follows:

order/index.php customer/index.php etc.

I want to reuse the same HTML and php code but I just want to make it easier to change the SQl table when I create a new table for each one.

I hope this makes since.

Thank you.

1 Answers

You can easily create a simple template file system with PHP.

In your template.php you should have something like

<html>
<head>...</head>
<body>
  ...
  <?php include $content; ?>
  ...
</body>
</html>

Then before you include template.php you assign $content variable to a filename or a path such as order.php or customer.php etc. With this everything in your template.php plus the file that is included will be shown.

Related