Specifications

The full script for making recommendations is shown in Listing 24.26 and 24.27. The main
script for making recommendations is called recommend.php (see Listing 24.26). It calls the
recommender function recommend_urls() from url_fns.php (see Listing 24.27).
LISTING 24.26 recommend.phpThis Script Suggests Some Bookmarks That a User
Might Like
<?
require_once(“bookmark_fns.php”);
session_start();
do_html_header(“Recommending URLs”);
check_valid_user();
$urls = recommend_urls($valid_user);
display_recommended_urls($urls);
display_user_menu();
do_html_footer();
?>
LISTING 24.27 recommend_urls() Function from url_fns.phpThis Script Works Out the
Actual Recommendations
function recommend_urls($valid_user, $popularity = 1)
{
// We will provide semi intelligent recommendations to people
// If they have an URL in common with other users, they may like
// other URLs that these people like
if (!($conn = db_connect()))
return false;
// find other matching users
// with an url the same as you
if (!($result = mysql_query(“
select distinct(b2.username)
from bookmark b1, bookmark b2
where b1.username=’$valid_user’
and b1.username != b2.username
and b1.bm_URL = b2.bm_URL
“)))
return false;
if (mysql_num_rows($result)==0)
return false;
Building Practical PHP and MySQL Projects
P
ART V
534
30 7842 ch24 3/6/01 3:34 PM Page 534