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.

602 Chapter 27 Building User Authentication <strong>and</strong> Personalization<br />

Figure 27.10<br />

The deletion script notifies the user of deleted bookmarks <strong>and</strong><br />

then displays the remaining bookmarks.<br />

As in the add_bms.php script, after the changes to the database have been made, you display<br />

the new bookmark list using get_user_urls() <strong>and</strong> display_user_urls().<br />

Implementing Recommendations<br />

Finally, you’re ready for the link recommender script, recommend.php.There are many<br />

different ways you could approach recommendations.You should perform what we call a<br />

“like minds” recommendation.That is, look for other users who have at least one bookmark<br />

the same as your given user.The other bookmarks of those other users might<br />

appeal to your given user as well.<br />

The easiest way to implement this as an SQL query is to use subqueries.The first<br />

subquery looks like this:<br />

select distinct(b2.username)<br />

from bookmark b1, bookmark b2<br />

where b1.username='".$valid_user."'<br />

<strong>and</strong> b1.username != b2.username<br />

<strong>and</strong> b1.bm_URL = b2.bm_URL)<br />

This query uses aliases to join the database table bookmark to itself—a strange but sometimes<br />

useful concept. Imagine that you actually have two bookmark tables, one called b1<br />

<strong>and</strong> one called b2. In b1, you look at the current user <strong>and</strong> his bookmarks. In the other<br />

table, you look at the bookmarks of all the other users.You are looking for other users

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

Saved successfully!

Ooh no, something went wrong!