13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Implementing User Functions<br />

713<br />

Listing 30.8<br />

Continued<br />

for($i = 0; $ifetch_array();<br />

array_push($list, array($row[0], $row[1]));<br />

}<br />

}<br />

return $list;<br />

}<br />

As you can see, this function requires an email address passed into it.This should be the<br />

email address of the subscriber that you are working with.The<br />

get_subscribed_lists() function also requires an email address as a parameter, but the<br />

get_all_lists() function does not for obvious reasons.<br />

Given a subscriber’s email address, you connect to the database <strong>and</strong> fetch all the lists<br />

the subscriber is not subscribed to.You use a LEFT JOIN to find unmatched items, <strong>and</strong><br />

you loop through the result <strong>and</strong> build the array row by row using the array_push()<br />

built-in function.<br />

Now that you know how this list is produced, let’s look at the action buttons associated<br />

with these displays.<br />

Viewing List Information<br />

The Information button shown in Figure 30.7 triggers the information action, which is<br />

as follows:<br />

case 'information':<br />

display_information($_GET['id']);<br />

break;<br />

To see what the display_information() function does, look at Figure 30.8.<br />

This function displays some general information about a particular mailing list <strong>and</strong> lists<br />

the number of subscribers <strong>and</strong> number of newsletters sent out to that list <strong>and</strong> available in<br />

the archive (more on that shortly).The code for this function is shown in Listing 30.9.<br />

Listing 30.9 display_information()Function from output_fns.php—This<br />

Function Displays List Information<br />

// diplay stored information about each list<br />

function display_information($listid) {<br />

if(!$listid) {<br />

return false;<br />

}<br />

$info=load_list_info($listid);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!