Đang chuẩn bị liên kết để tải về tài liệu:
PHP and MySQL Web Development - P108
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
PHP and MySQL Web Development - P108: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Implementing Recommendations 507 where b1.username valid_user and b1.username b2.username and b1.bm_URL b2.bm_URL This query uses aliases to join the database table bookmark to itself a strange but sometimes useful concept. Imagine that there are actually two bookmark tables one called b1 and one called b2. In b1 we look at the current user and his bookmarks. In the other table we look at the bookmarks of all the other users.We are looking for other users b2.username who have an URL the same as the current user b1.bm_URL b2.bm_URL and are not the current user b1.username b2.username . This query will give us a list of like-minded people to our current user. Armed with this list we can search for their other bookmarks with the following query select bm_URL from bookmark where username in sim_users and bm_URL not in user_urls group by bm_URL having count bm_URL popularity The variable sim_users contains the list of like-minded users. The user_urls variable contains the list of the current user s bookmarks if b1 already has a bookmark there s no point in recommending it to him. Finally we add some filtering with the popularity variable we don t want to recommend any URLs that are too personal so we only suggest URLs that a certain number of other users in the list of like-minded users have bookmarked. If we were anticipating a lot of users using our system we could adjust popularity upwards to only suggest URLs have been bookmarked by a large number of users. URLs bookmarked by many people might be higher quality and certainly have more general appeal than an average Web page. 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.php This Script Suggests Some Bookmarks That a User Might Like php require_once bookmark_fns.php session_start .