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.

716 Chapter 30 Building a Mailing List Manager<br />

This function runs three database queries to collect the name <strong>and</strong> blurb for a list from<br />

the lists table, the number of subscribers from the sub_lists table, <strong>and</strong> the number of<br />

newsletters sent from the mail table.<br />

Viewing List Archives<br />

In addition to viewing the list blurb, users can look at all the mail that has been sent to a<br />

mailing list by clicking on the Show Archive button.This activates the show-archive<br />

action, which triggers the following code:<br />

case 'show-archive':<br />

display_items('Archive For '.get_list_name($_GET['id']),<br />

get_archive($_GET['id']), 'view-html',<br />

'view-text', '');<br />

break;<br />

Again, this function uses the display_items() function to list the various items of mail<br />

that have been sent to the list.These items are retrieved using the get_archive() function<br />

from mlm_fns.php.This function is shown in Listing 30.11.<br />

Listing 30.11 get_archive()Function from mlm_fns.php—This Function Builds an<br />

Array of Archived Newsletters for a Given List<br />

function get_archive($listid) {<br />

//returns an array of the archived mail for this list<br />

//array has rows like (mailid, subject)<br />

$list = array();<br />

$listname = get_list_name($listid);<br />

$query = "select mailid, subject, listid from mail<br />

where listid = '".$listid."' <strong>and</strong> status = 'SENT'<br />

order by sent";<br />

if($conn=db_connect()) {<br />

$result = $conn->query($query);<br />

if(!$result) {<br />

echo "Unable to get list from database.";<br />

return false;<br />

}<br />

$num = $result->num_rows;<br />

for($i = 0; $ifetch_array();

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

Saved successfully!

Ooh no, something went wrong!