For Quite a while now you’ve been focusing on some basic details a user the user’s information and as an extension of that information, the user’s profile picture. You’ve become familiar with PHP and MySQL, figured out not just one but two ways to deal with one of the most common PHP issues-image loading and you’ve managed to keep things looking good throughout. These aren’t small
accomplishments; they’re very much big ones.
As a user you can set up a profile and specify some basic information. If you’re an administrator you might want to see how many users are in your system, delete a malicious user or update a picture because it’s not Quite socially palatable. You can do all that through your MySQL command line, but in the real world of web
applications, most administrators aren’t keeping a MySQL terminal running in the corner of their monitor.
Instead, they have administrative interfaces. They can list all the users in a system; check some boxes here and there and mass delete users; and see any user they want, all through a nice, clean web interface. You can give your web application the same nice features
When you start thinking about an administrative interface, you run into all sorts of interesting problems. You need to use different types of SQL Queries. You have to mix together a lot more PHP and MySQL with your HTML because you ll have to list every user from the database, one at a time. You have to deal with DELETE statements and a lot more WHERE statements.
In this chapter you’ll take everything you know and push further. There are not many radically new techniques to learn but there are lots of important variations on what you already do know. 50 why wait any longer or settle for MySQL as your admin interface? Time to set up a better more visual way to keep up with your users.
Thinking about-What You Need as an Admin
As usual, the first step is to layout what you need and rough out the broad strokes of how things look and interact. You can start with a few bullet points, figure out the screens you’re going to need, and throw together some mock-ups either in HTML or even a tool such as Photoshop.
Because your app is straightforward, all you’ll need for the moment is the following:
• A form that lists all the users in the system
– A link to each user’s profile page
• The ability to delete a user
• The ability to update or change a user’s information
• A means of giving other users administrative privileges
That last one is going to take quite a bit of work and create some unique headaches
with which you’ll have to deal, so let’s save it for a bit later (that is, the next chapter).
But you can get started on the rest. right now.
(User Interface) Brevity Is Still the Soul of Wit
You could build up a complex system of pages that let you manage all these interactions. show_user.php could figure out if you’re an admin and selectively show a Delete button you could build up an entire administrative menu in fact. Then again sometimes the simple things are the best things. On top of that, the Web rewards fewer clicks as a general rule. If you can provide a single page that accommodates the major required functionality you probably should keep(l things to just that single page .
In this case you keep it concise. You can list users in a simple sequence turn the name of each user into a link to her profile page and even add a delete button after each user. You’ll still have to deal with changing a user’s information, but three items on one form is a good start.
Looking at the HTML for this page is instructive. You can immediately see that there’s a lot of duplication and PHP is good at reducing duplication:
want to spend a or of time on the front end before you’ve done any code Decisions you make as you work on your code might affect future decisions and functionality.
The answer Create a short list of features you hope to implement in the future This doesn’t need to be anything fancy a text document or even something on your iPad or iPhone sitting next to your workstation are all fine. Then add to or update that list as you go and as features and functionality change Hopefully just having these “next version” features handy will help you think clearly about how decisions you make today might help you or hurt you when you get around to writing more code tomorrow, next week or next month.
For now here are just a few things that might be nice to add once the basic functionality is in place
• Improve the user interface setting up the different “columns” of data in a more intuitive fashion and getting those delete “X” buttons to align.
• Add user profile pictures so that you can get a little better graphical view of each user in the admin interface.
• Allow for multiple user selection and deletion on one screen.
• Add a confirmation dialog box or pop-up message when a user is selected for deletion to avoid accidental deletions.
You’can add your own ideas to this list but this is certainly a good starting point. Maybe you’ll code these up and maybe you won’t, but now at least you can make decisions that will help allow for these features, rather than get in the way of them.