After about 1/2 hr, I remembered that I used to be a pretty good PHP programmer. This is a task that PHP can handle very easily.
The question really was this. Where is the best place for this data to live? On the html page or in a database? The answer?, almost always in a DB.
Why put the list data in a DB table when I could just put it directly into the page?
- 1 - More flexible. I can build the *list in many places, since data is in a DB table
- 2 - Less code. I can build a simple loop and use far less html code to output the list.
- 3 - Sorting options. I can reorder the list a couple different ways from the DB.
- 4 - More extensible. I can add things to it.
The table code in the html page spanned 230 lines. It was at this point that I said "you are a dummy, stop doing this and put the data in a table and convert this htmp page to a php page and use a simple for loop to output the data.
Create the table in the DB
Using MySQL workbench, I created a simple table called teachers, with these columnsPopulate the table - I did this in MySQL workbench - edit table mode.
Create a function in my DAO.php file to pull the data from the new table
Connect the html page, which is now a php page to the DAO.php
Call the function from the page and dump the result - for testing purposes.
The result.








No comments:
Post a Comment