Skip to content
Advertisement

Insert PHP into code web design without a large block of code. Solved [closed]

I am fairly new to PHP/SQL I have been lightly playing with it for a year or so and I decided to start getting into it more.

First question I guess would be, is inserting into web design. Is there ways to place it so I am not putting in a block of code more like one line through an include? I would like it so a admin user database table isn’t coded in my home.php. I am probably asking super simple questions I just don’t like having the below in my code and it getting hard to find things.

JavaScript

Advertisement

Answer

The simplest solution is to move the PHP code to another file say “helper_functions.php”. So the result would look something like this :

JavaScript

And in your view file just include the helpers file and call the function like so :

JavaScript

This is by no means the best solution. If you want to write much cleaner, seperated and organised code, I suggest you read about MVC architecture.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement