Professional CodeIgniter

(singke) #1

Chapter 8: Last-Minute Upgrades


265


One last upgrade is needed before you can move on. Previously in this chapter, the idea was floated that
removing duplicates from the e - mail addresses, before sending out a newsletter blast, might be a good
idea. There are two ways of accomplishing this task, and either is good depending on where you ’ re at in
a project.

A good way to remove duplicates is to do it when people subscribe. Run a quick check on
subscribe and only enter them in the system if they ’ re brand new.

Another way to achieve the same goal is to run a quick check right before an e - mail blast
goes out.

When you stop and think about it, though, what if someone has subscribed multiple times in the
database (through no fault of their own or because of simply not remembering an earlier subscribe
attempt). If they ever unsubscribe, they unsubscribe once, but may continue to get more mailings in the
future. So the best way to handle this is to run a quick check before you subscribe someone.

The solution is simple: rewrite the createSubscriber() function in MSubscribers such that you run a
quick count_all_results() query. If the count comes back as 0, then run your insert(). Otherwise,
don ’ t do anything.

function createSubscriber(){
$this- > db- > where(‘email’, $_POST[‘email’]);
$this- > db- > from(‘subscribers’);
$ct = $this- > db- > count_all_results();

if ($ct == 0){
$data = array(
‘name’ = > $_POST[‘name’],
‘email’ = > $_POST[‘email’]
);

$this- > db- > insert(‘subscribers’, $data);
}
}

Meeting with the Client


After you ’ re done with all the little tweaks, you take Claudia on a quick tour of the new functionality.
She loves the fact that she can add new pages and create HTML e - mails. She knows she can now start
adding real products and data to the web site.

“ As you work with the site, you ’ re going to notice a few things, ” you tell her. “ For example, you may
need more database fields to store information, or the WYSIWYG editor might need more options added
to it. Just make a list and we ’ ll talk in a few days. ”

“ What are you going to be doing until then? ” she asks.


Free download pdf