13.09.2016 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Implementing User Functions<br />

717<br />

Listing 30.11<br />

Continued<br />

$arr_row = array($row[0], $row[1],<br />

$listname, $listid);<br />

array_push($list, $arr_row);<br />

}<br />

}<br />

return $list;<br />

}<br />

Again, this function gets the required information—in this case, the details of mail<br />

that has been sent—from the database <strong>and</strong> builds an array suitable for passing to the<br />

display_items() function.<br />

Subscribing <strong>and</strong> Unsubscribing<br />

On the list of mailing lists shown in Figure 30.7, each list has a button that enables users<br />

to subscribe to it. Similarly, if users use the Show My Lists option to see the lists to<br />

which they are already subscribed, they will see an Unsubscribe button next to each list.<br />

These buttons activate the subscribe <strong>and</strong> unsubscribe actions, which trigger the<br />

following two pieces of code, respectively:<br />

case 'subscribe':<br />

subscribe(get_email(), $_GET['id']);<br />

display_items('Subscribed Lists',<br />

get_subscribed_lists(get_email()),<br />

'information', 'show-archive', 'unsubscribe');<br />

break;<br />

case 'unsubscribe':<br />

unsubscribe(get_email(), $_GET['id']);<br />

display_items('Subscribed Lists',<br />

get_subscribed_lists(get_email()),<br />

'information', 'show-archive', 'unsubscribe');<br />

break;<br />

In each case, you call a function (subscribe() or unsubscribe()) <strong>and</strong> then redisplay a<br />

list of mailing lists the user is now subscribed to by using the display_items() function<br />

again.<br />

The subscribe() <strong>and</strong> unsubscribe() functions are shown in Listing 30.12.

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

Saved successfully!

Ooh no, something went wrong!