Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall
In order to increase the inner chain, also in order to facilitate users to browse more relevant web pages, many sites have set up "related reading", or "guess you like" Such columns, however, I found that there are a lot of websites related to reading each page is the same, and sometimes not strong, pondering upon the discovery, The original webmaster settings related reading is actually 6184.html "> data table of the recent records, it uses the SQL query statement is roughly like this:
Select Id,title from MYTB ORDER BY id DESC LIMIT 8
There are two obvious flaws in such queries:
1. The results found are not guaranteed to be relevant;
2. A large number of pages will be used for the same related reading, the user experience is not good, but also occupy other data exposure opportunities.
In fact, this query statement is slightly optimized, you can improve the "related reading" method as follows:
Analysis: First of all, to determine the current page data ID in the entire table where the position, divided into three cases (take 8 records as an example):
1. The current ID small Yu Shen order 4th article ID;
2. The current ID is greater than the 4th ID in descending order;
3. The current ID is between the two.
First get the maximum (MAXID) and minimum (MiniD) IDs for the datasheet:
Select Max (ID) maxid from MYTB;
Select min (id) MiniD from MYTB;
Then use judgment statements in your program, such as in PHP:
$num = $id +4;
$where = "ORDER BY id DESC";
if ($id < $MAXID-4 && $id > $minid +4) $where = "and id< $num ORDER by id DESC";
if ($id < $minid +4) $where = "and id> $minid ORDER by ID ASC";
$sql = "Select Id,title from MYTB where ID!= $id $where limit 8";
The value taken out by the above method will change with the current ID, especially if you upload the article, if the relevance of the article next to upload, then the relevance will be stronger.
Of course, can also use the way to match keywords, but an article often has several key words, not to mention that the relevant reading is often carried out under the same column, query efficiency is far from the above provided methods strong.
By the Large network (http://www.phpdo100.com) provided, reproduced please indicate the source.