Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How phpcms V9 invokes the latest content in multiple models

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how phpcms V9 invokes the latest content in multiple models. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

In many cases, you want to call the latest content under multiple models, but because the V9 model uses sub-tables to store, it is very troublesome to use GET to IN catid with tables to query, so you can use the following methods:

Step one:

Phpcms\ libs\ functions\ extention.func.php

Add to it

Function news ($limit= ", $modelid=", $where= ") {$db=pc_base::load_model ('content_model'); if ((strpos ($modelid,", ") > = 0)) {$modelid=explode (", ", $modelid); $midarr=$dot=''; foreach ($modelid as $mid) {$midarr=$midarr.$dot.$mid; $dot=',';} $sq=" `modelid` IN ({$midarr}) ";} else {$sq=" `modelid` = {$modelid} " } $db- > table_name='v9_model'; $models=$db- > select ($sq, "tablename"); $sql=''; $lianhe=''; foreach ($models as $name) {$sql=$sql.$lianhe. "SELECT id,catid,title,url,inputtime FROM v9 _ {$name ['tablename']}"; $lianhe=' UNION ALL';} $time=time (); $sql=$sql. ". $where." Order by inputtime desc limit ". $limit; $allnews=$db- > query ($sql); while ($r = $db- > fetch_array ($allnews)) {if ($keyfield) {$key = $r [$keyfield]; $array [$key] = $r;} else {$array [] = $r;}} return $array [0];}

What you need to pay attention to in the above code is the inner table prefix. Here is V9. Change it to your own table prefix when using it. The default is V9.

Step 2:

The method of calling is:

{loop $recent $r} {str_cut ($r [title], 54, ")} {/ loop} {/ pc}

Explanation:

The red number is the number of calls, with 8 calls starting from 0.

Blue digital model ID, not column ID, for multiple models, separate

This is the end of this article on "how phpcms V9 invokes the latest content in multiple models". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report