雷达智富

首页 > 内容 > 网页技术 > 正文

网页技术

循环字段的使用方式

2021-11-19 226

也许大家不了解循环字段,但是大家应该知道齐博内容发布文章的时候有个副标题,$rsdb[subhead],这个字段可以在分页的时候让他不同的页面不同的标题,那么如果我想多一个这样功能的字段,在发布信息的时候同时两种副标题,改换成其他的代码应用,那么我们就开始创建这样的字段。

首先到数据库去创建这样相同的字段

打开数据表 qb_reply 字段 subhead 插入一个 fenyedm

记住代码功能要相同的,如下图

然后打开artic_function.php

查找:subhead

得到下面的代码

if($j==1&&($type=='postnew'||$type=='edit'))
		{
			if($type=='postnew')
			{
				$db->query("INSERT INTO `{$_pre}reply` ( `aid` ,`fid` ,`uid` , `content` ,`subhead`,`topic`) VALUES ( '$aid', '$fid','$lfjdb[uid]', '$content','$postdb[subhead]','1')");
			}
			elseif($type=='edit')
			{
				$db->query("UPDATE `{$_pre}reply` SET fid='$fid',content='$content',subhead='$postdb[subhead]' WHERE rid='$rid'");
			}
		}
		else
		{
			$db->query("INSERT INTO `{$_pre}reply` ( `aid` ,  `fid` ,`uid` ,  `content` ,`subhead`,`topic`) VALUES ( '$aid','$fid','$uid','$content','$postdb[subhead]','0')");
		}
	}
	@extract($db->get_one("SELECT COUNT(*) AS NUM FROM `{$_pre}reply` WHERE `aid`='$aid'"));
	$db->query("UPDATE `{$_pre}article` SET pages='$NUM' WHERE aid='$aid'");
}

在相应的地方加入,对照检查我创建的字段fenyedm

if($j==1&&($type=='postnew'||$type=='edit'))
		{
			if($type=='postnew')
			{
				$db->query("INSERT INTO `{$_pre}reply` ( `aid` ,`fid` ,`uid` , `content` ,`subhead`,`fenyedm`,`topic`) VALUES ( '$aid', '$fid','$lfjdb[uid]', '$content','$postdb[subhead]','$postdb[fenyedm]','1')");
			}
			elseif($type=='edit')
			{
				$db->query("UPDATE `{$_pre}reply` SET fid='$fid',content='$content',subhead='$postdb[subhead]',fenyedm='$postdb[fenyedm]' WHERE rid='$rid'");
			}
		}
		else
		{
			$db->query("INSERT INTO `{$_pre}reply` ( `aid` ,  `fid` ,`uid` ,  `content` ,`subhead`,`fenyedm`,`topic`) VALUES ( '$aid','$fid','$uid','$content','$postdb[subhead]','$postdb[fenyedm]','0')");
		}
	}
	@extract($db->get_one("SELECT COUNT(*) AS NUM FROM `{$_pre}reply` WHERE `aid`='$aid'"));
	$db->query("UPDATE `{$_pre}article` SET pages='$NUM' WHERE aid='$aid'");
}

接着打开admin/post.php

查找subhead

if(!$rs[subhead]){
$rs[subhead]=$rsdb[title];
}

添加代码

if(!$rs[subhead]){
$rs[subhead]=$rsdb[title];
$rs[fenyedm]=$rsdb[title];
}

继续查找

unset($rsdb[content],$rsdb[subhead]);

添加

unset($rsdb[content],$rsdb[subhead],$rsdb[fenyedm]);

然后在你的提交页admin/template/post/post.htm

打开

<tr bgcolor="#FFFFFF" class="othertr"> 
            <td  width="15%">副标题:</td>
            <td  width="85%"> 
              <input type="text" name="postdb[subhead]" size="80" value="$rsdb[subhead]">
            </td>
          </tr>

下面添加

<tr bgcolor="#FFFFFF" class="othertr"> 
            <td  width="15%">副标题:</td>
            <td  width="85%"> 
              <input type="text" name="postdb[subhead]" size="80" value="$rsdb[subhead]">
            </td>
          </tr>
          <tr bgcolor="#FFFFFF" class="othertr"> 
            <td  width="15%">自定义循环代码:</td>
            <td  width="85%"> 
              <input type="text" name="postdb[fenyedm]" size="80" value="$rsdb[fenyedm]">
            </td>
          </tr>

现在就大功告成了

也许这个功能对你暂时无用,但是在你网站时间做久了,在很多地方你会发现循环字段是你必不可少的。

赞一波!4

文章评论

全部评论