PHP Page 4 - Creating a Searchable Inventory System: Setting Up Your Database and User Interface |
There are a number of ways we could go about setting up our PHP code to handle the task at hand. However, since the ideas we are discussing are not limited to the particular application we are developing (the computer hardware storefront), it would be helpful to develop code that is as re-usable as possible. In order to do that, we will first need to take a moment to think about what exactly it is that we need PHP to do. Our first focus is on the search form itself. For our example application, that form will comprise three SELECT menus and a text input field. Creating the text input field is simple, but our PHP will need to retrieve, sort, and display a proper set of options for each of the SELECT menus. To make things even more interesting, two of those menus (“Sub Categories” and “Manufacturers”) will be dependent upon values found within the first (“Categories”), a feature that will require additional JavaScript and PHP code to function. As previously mentioned, our goal is to create code that is reusable, and a good first step for doing that is defining the proper code flow. Let’s go ahead and create the following files: helper.php // holds PHP & Javascript to dynamically update As you can see, each file has a specific task/function. The “index.php” file we have already discussed, so let’s now take a look at the “inc.conf.php” page. At this point all we will need to do within our conf file is open a database connection: <?php This database connection will be used by PHP code found within other files (“helper.php” and “search.php” mainly), but instantiating it here helps keep things a little cleaner and easier to update, should our connection information change. Our “inc.core.php” file should also look pretty barebones at this point: <?php # turn off error reporting on undefined indexes # include the core configuration page # include the Search helper class That’s it for our configuration and includes files for the time being, although we will come back to them with some enhancements as the article series continues. Summing things Up We’ve now put all of the pieces into place, and we’re ready to start assembling our search interface using the helper Search class we’ll be creating (“search.php”). So far our page looks pretty empty, but we’ll fill it up quickly once things get started. Your “index.php” file should currently display the following: http://portfolio.boynamedbri.com/devshed/search/part_1/ You’re now ready to move on to part two, and begin working on the Search class.
blog comments powered by Disqus |