The following post is being written because today I’ve been annoyed, very annoyed. I’ve been working on updates to a previous developers mini CRM system that I inherited, unfortunately. Basically, the customer wanted to amend the list of options that appear in a HTML select box, on pretty much every page. In this case, 24 pages.
Ok, easy job – or so I thought. If the previous developer hadn’t been a total mong this simple update would have taken a minute or so – simply update a common function, database or global array to repopulate the drop down list options. No luck in the least – the developer had hard coded each drop down into every page, using HTML – **** great! So I just spent close to 40 minutes wading through include files and HTML to make my changes – so unecessary.
So, what follows is a very simple method to have a common drop down list that will be included on any page you want, with the data stored in a global array (could be a database, but a global array is quickest:
The include, model or config file – simple an associative array that will be accessible throughout your application (lets call this file includes.php):