mercredi 27 janvier 2016

Best code structure for pulling data, adding logic for how it is displayed

My current task is to create a dynamic email based on data from a database. The only issue is that I am going to have to add logic within the code to display what data and where.

My main question is what is probably the best way of structuring this code? Should I use 300+ if statements (i really don't want to), cluttered loops to gather data from arrays, or something that involves using OOP styled PHP?


Here's what I am trying to achieve:

For every order that is made online, there is an unique order-id attached to it.
All order data is inserted into a MySQL database
A few days after they order online, we send them an email with instructions based on the data in the database.

For example:

Order #10 purchased a hotel stay on 02/05
that includes a shuttle ride to the grocery store,
at the specific time of 3:45 pm

In the database there would be a column for: order-id, check-in-date, shuttle-ride, shuttle-ride-location and shuttle-pickup-time

base on that data, in the email there needs to be instructions on what to do, like this:

02/05/16 : Arrive at the hotel, check in with your order id number, at 3:30 pm head to the hotel lobby to wait until 3:45 pm for your shuttle ride to the grocery store, at xx:xx xx call the driver to pick you up and bring you back to your hotel...*

02/06/16 : Check out of hotel at xx:xx xx, head to the airport X, etc.

Is there a proper way of achieving this in PHP, a certain type of style that would be considered more efficient and cleaner structure?

Thanks.

Aucun commentaire:

Enregistrer un commentaire