The example in this article describes the implementation method of cross-table query related links in Imperial CMS. Share it with everyone for your reference. The specific analysis is as follows:
Official related links are not flexible, the style cannot be modified arbitrarily and cannot cross tables. Many people want to make related links across tables. For example, news and info have several articles with keywords. 'Beijing', then how to call these articles with the same keyword? I wrote a custom function for this purpose.
It is recommended to study "Empire cms tutorial"
A small range of calls can be used in this category, and a slightly larger range can call the same table If the article is larger, you can call the article of the specified table. You can choose the number of articles to be called. In fact, you can also upgrade, such as specifying the number of articles to call a certain table, the order of that table, etc. The function has no style. You can understand it a little bit. The code can be modified by yourself, it is not particularly difficult. If anyone has upgraded this function, you can share it with everyone.
The code is as follows:
fetch1("select tagid,tagname,num,isgood,cid from {$dbtbpre}enewstags where tagname='". $tag_all[$i]."' order by tagid limit 1") ; $tag_id[$i]=$r_1_1['tagid'] ; //tag的ID $tag_num[$i]=$r_1_1['num'] ; //tag下的文章数量 if($tag_num[$i]>=$eq_num){//如果TAG下的文章数量比平均的数量大或者等于,那么TAG的文章数量取平均值 $tag_num[$i] = $eq_num ;//重新赋值 }else{//如果TAG下的文章小于平均值,那么TAG取原有的文章数量。同时重新赋值平均值。 $eg_tag= $eq_num-$tag_num[$i] ; $eq_num += $eg_tag ; } //比如说有3个TAG,每个TAG下有4篇文章,现在指定要显示10篇文章,那么每个TAG要拿出4篇,共有12篇文章 //3个TAG,每个TAG下有3篇文章,现在指定要显示10篇文章,那么每个TAG要拿出3篇文章,共有9篇文章 //3个TAG,A有2篇文章,B有5篇文章,C有3篇文章,现在要显示10篇文章,那么A拿出2篇文章,B拿出5篇文章,C拿出3篇文章, 共有10篇文章 //如果 A、B、C中除了当前文章,还有相同的文章,那么会扣除重复的那篇文章,只取一次。所以指定的数量会有偏差 for($i_n=0;$i_nquery("select tid,classid,id,mid from {$dbtbpre}enewstagsdata where tagid='".$tag_id[$i]."' order by classid "); $ri=1 ; while($r=$empire->fetch($sql)) { $tbname_all[$r['tid']]=$class_r[$r['classid']]['tbname'] ; if($tbname_all[$r['tid']]==$tbname_num[$i_n] && $ri <= $tag_num[$i] && $navinfor['classid']!=$r['classid'] && $navinfor['id']!=$r['id']){ if($ck==1&&$navinfor['classid']==$r['classid']){ $tbname_all_r[$r['tid']]=$class_r[$r['classid']]['tbname'] ; $classid_id[$r['tid']]=$r['classid'] . '_' . $r['id'] ; $classid_all[$r['tid']]=$r['classid'] ; $id_all[$r['tid']][$r['classid']]=$r['id'] ; }elseif($ck==2&&$class_r[$navinfor['classid']]['tbname']==$class_r[$r['classid']]['tbname']){ $tbname_all_r[$r['tid']]=$class_r[$r['classid']]['tbname'] ; $classid_id[$r['tid']]=$r['classid'] . '_' . $r['id'] ; $classid_all[$r['tid']]=$r['classid'] ; $id_all[$r['tid']][$r['classid']]=$r['id'] ; }elseif($ck==3){ $tbname_all_r[$r['tid']]=$class_r[$r['classid']]['tbname'] ; $classid_id[$r['tid']]=$r['classid'] . '_' . $r['id'] ; $classid_all[$r['tid']]=$r['classid'] ; $id_all[$r['tid']][$r['classid']]=$r['id'] ; } $ri++; } } } } $classid_id_x=array_unique($classid_id);//去除重复的值 //去除重复的值,不同的TAG会有相同的文章。所以去除重复的值。比如A篇文章里面都有"北京","奥运",两个关键词, B篇文章里面也有"北京","奥运"在不去除重复的情况下,A篇的相关链接会出现两次B文章。所以必须去除其中一个。 arsort($classid_id_x); //按键名排列,倒序 $tid_tid=array_keys($classid_id_x) ;//取出键名重新排列,键名即为TAG的ID:tid shuffle($tid_tid);//顺序打乱,重新排 $tid_tid_num=count($tid_tid) ; if($num<$tid_tid_num) $tid_tid_num=$num+1 ;//由于去除了本文章,所以再加一条弥补 for($i_tid=0;$i_tid<$tid_tid_num;$i_tid++){ $tid=$tid_tid[$i_tid]; $classid=$classid_all[$tid]; $id=$id_all[$tid][$classid]; if($id==$navinfor['id']) continue ; //如果是本文章,相关链接里面就不用再放了。 $tbname=$tbname_all_r[$tid]; $r_1_2 =$empire->fetch1("select title,smalltext,titleurl,dp_jt,dp_dwz from {$dbtbpre}ecms_$tbname where id='".$id."' order by newstime limit 1") ; ////////显示样式在这修改 echo $r_1_2['title'].' ' ; //////// } } ?> /** **/
I hope this article will be helpful to everyone The Empire CMS website builder helps.
The above is the detailed content of The most practical method to implement cross-table query related links in Empire CMS. For more information, please follow other related articles on the PHP Chinese website!