Specifications
• $title is the title that appears at the top of the table—in the case shown in Figure 28.7,
we are passing in the title Unsubscribed Lists, as shown in the previously discussed code
snippet for the action “Show Other Lists”.
• $list is an array of items to display in each row of the table. In this case, it is an array
of the lists the user is not currently subscribed to. We are building this array (in this case)
in the function get_unsubscribed_lists(), which we’ll discuss in a minute. This is a
multidimensional array, with each row in the array containing up to four pieces of data
about each row. In order, again:
• $list[n][0] should contain the item id, which will usually be a row number. This
gives the action buttons the id of the row they are to operate upon. In our case, we
will use ids from the database—more on this in a minute.
• $list[n][1] should contain the item name. This will be the text displayed for a
particular item. For example, in the case shown in Figure 28.7, the item name in
the first row of the table is PHP Tipsheet.
• $list[n][2] and $list[n][3] are optional. We use these to convey that there is
more information. They correspond to the more information text and the more
information id, respectively. We will look at an example using these two parame-
ters when we come to the View Mail action in the “Implementing Administrative
Functions” section.
We could, as an alternative, have used keywords as indices to the array.
The third, fourth, and fifth parameters to the function are used to pass in three actions that will
be displayed on buttons corresponding to each item. In Figure 28.7, these are the three action
buttons shown as Information, Show Archive, and Subscribe.
We got these three buttons for the Show All Lists page by passing in the action names,
information, show-archive, and subscribe. By using the display_button() function, these
actions have been turned into buttons with those words on them, and the appropriate action
assigned to them.
Each of the Show actions calls the display_items() function in a different way, as you can
see by looking back at their actions. As well as having different titles and action buttons, each
of the three uses a different function to build the array of items to display. Show All Lists uses
the function get_all_lists(), Show Other Lists uses the function get_unsubscribed_
lists(), and Show My Lists uses the function get_subscribed_lists(). All these functions
work in a similar fashion. They are all from the mlm_fns.php function library.
We’ll look at get_unsubscribed_lists() because that’s the example we’ve followed so far.
The code for the get_unsubscribed_lists() function is shown in Listing 28.7.
Building Practical PHP and MySQL Projects
P
ART V
682
34 7842 CH28 3/6/01 3:46 PM Page 682