Introduction: This is a detailed page for adding popular search keywords to phpcms V9. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 351602 'rolling = 'no'>
Phpcms V9 is currently in use, and popular search keywords need to be displayed. Google has not found a complete solution.
Or DIY.
Through observation, we can find that the system comes with a keyword model, but it is not implemented.
It may be in the next version ~ DIY started with/phpcms/model/keyword_model.class.php.
Let's take a look at the content of keyword_model.class.php.
Defined ('in _ phpcms ') or exit ('no permission resources .');
Pc_base: load_sys_class ('model', '', 0 );
Class keyword_model extends model {
Public $ table_name = '';
Public Function _ construct (){
$ This-> db_config = pc_base: load_config ('database ');
$ This-> db_setting = 'default ';
$ This-> table_name = 'keyword ';
Parent: :__ construct ();
}
}
SlaveCodeWe can see that the keyword table name is keyword, but we do not see such a table name in the database.
Refer to the relevant search data table tb_search_keyword (I used TB as the table prefix during installation)
Create a popular search keyword data table keyword
Set foreign_key_checks = 0;
------------------------------
-- Table structure for 'tb _ keyword'
------------------------------
Drop table if exists 'tb _ keyword ';
Create Table 'tb _ keyword '(
'Keyword' char (20) not null,
'Typeid' tinyint (4) not null default '0 ',
'Searchnums' int (10) unsigned not null default '0 ',
Primary Key ('keyword '),
Unique key 'keyword' ('keyword ')
) Engine = MyISAM default charset = GBK;
In this way, the data table is created, and the next step is to add and call the data.
Open the file/phpcms/models/search/index. php
Find
// If the search function is enabled
If ($ setting ['relationenble ']) {
Add the following code to it:
// Add the search keyword record imbin 2011/9/13
If (! Empty ($ result )){
$ This-> keyword_log_db = pc_base: load_model ('keyword _ model ');
$ Res = $ this-> keyword_log_db-> get_one (Array ('keyword' => $ Q, 'typeid' => $ typeid ));
If ($ res ){
// Number of keyword searches + 1
$ This-> keyword_log_db-> Update (Array ('searchnums' => '+ = 1'), array ('keyword' => $ q ));
} Else {
$ This-> keyword_log_db-> insert (Array ('keyword' => $ Q, 'typeid' => $ typeid, 'searchnums' => 1 ));
}
}
In this way, the search keyword is added.
Let's take a look at the implementation of the template call. I use the get tag.
First, check the search result page:/phpcms/templates/default/search/list.html
{PC: Get SQL = "select keyword, typeid from tb_keyword where typeid = $ typeid and searchnums> 5 order by rand ()" num = "5" return = "keywords "}
{Loop $ keywords $ K =>$ v} <a href = "/index. php? Typeid = {$ V ['typeid']} & M = SEARCH & C = index & A = init & Q = {$ V ['keyword']} "> {$ v ['keyword']} </a >{/ loop}
{/PC}
I used random sorting here, because I don't want to see the same sorting every time.
Attach the SQL statement sorted by search times: Select keyword, typeid from tb_keyword where typeid = $ typeid order by searchnums DESC
If you are calling on the homepage, remove $ typeid. BTW: If you want to remove $ typeid from the non-search result page
{PC: Get SQL = "select keyword, typeid from tb_keyword order by searchnums DESC" num = "8" return = "keywords "}
{Loop $ keywords $ K =>$ v} <a href = "/index. php? Typeid = {$ V ['typeid']} & M = SEARCH & C = index & A = init & Q = {$ V ['keyword']} "> {$ v ['keyword']} </a >{/ loop}
{/PC}
OK. DIY is complete!
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/351602.html pageno: 3