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.

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

Listing 27.26<br />

Might Like<br />

recommend.php— This Script Suggests Some Bookmarks That a User<br />

<br />

Listing 27.27 recommend_urls()Function from url_fns.php—This Function<br />

Works Out the Actual Recommendations<br />

function recommend_urls($valid_user, $popularity = 1) {<br />

// We will provide semi intelligent recommendations to people<br />

// If they have an URL in common with other users, they may like<br />

// other URLs that these people like<br />

$conn = db_connect();<br />

// find other matching users<br />

// with an url the same as you<br />

// as a simple way of excluding people's private pages, <strong>and</strong><br />

// increasing the chance of recommending appealing URLs, we<br />

// specify a minimum popularity level<br />

// if $popularity = 1, then more than one person must have<br />

// an URL before we will recommend it<br />

$query = "select bm_URL<br />

from bookmark<br />

where username in<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 />

<strong>and</strong> bm_URL not in<br />

(select bm_URL<br />

from bookmark

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

Saved successfully!

Ooh no, something went wrong!