首页 >后端开发 >php教程 >怎么把单个和双个和在一起呀?

怎么把单个和双个和在一起呀?

WBOY
WBOY原创
2016-06-20 12:50:171066浏览

		$new['Name'] = strval($_POST['name']);		$tags = strval($_POST['tag']);		$new['Status'] = intval($_POST['status']);		$new['DisplayOrder'] = intval($_POST['order']);		if (!$new['Status'] == 1 || !$new['Status'] == 2)		{			self::output(['title'=>'参数非法','type'=>'error']);		}		$mid = intval($_POST['mid']);              if(strstr($tags,','))		{			$tagstr=[];			$pdo_r = Bridge::pdo(Bridge:: DB_TAG_R);			$tagsDB = explode(',',$tags);			foreach ($tagsDB as $k=>$v)			{				$v=trim($v);				$query = $pdo_r->prepare("SELECT TagNameId FROM `TagName` WHERE TagName = :channelName");				$query->execute([':channelName' => $v]);				$rs = $query->fetch();				if(!$rs)				{					$error_msgs = '该“'.$v.'”,'.'标签不存在';					self::output(['title'=>"$error_msgs",'type'=>'error']);				}				$tagstr[]=$rs['TagNameId'];			}		}		else{			$v=trim($tags);			$pdo_r = Bridge::pdo(Bridge:: DB_TAG_R);			$query = $pdo_r->prepare("SELECT TagNameId FROM `TagName` WHERE TagName = :channelName");			$query->execute([':channelName' => $v]);			$rs = $query->fetch();			if (!$rs)			{				$error_msgs = '该“'.$v.'”,'.'标签不存在';				self::output(['title'=>"$error_msgs",'type'=>'error']);			}			$tagstr[]=array_unique($rs['TagNameId']);		}		$new['Tags'] = serialize($tagstr);		$pdo_w = Bridge::pdo(Bridge::DB_HEALTH_W);		$re = $pdo_w->update('ArticleChannel', $new, ['ChannelId' => $mid]);			$this->adminLog('标签修改', $mid, 'update', serialize($new));		if ($re > 0)		{			self::output(['title'=>'操作成功','type'=>'success']);		}		self::output(['title'=>'操作失败','type'=>'error']);	}


回复讨论(解决方案)

去掉 if(strstr($tags,',')) 及 if(strstr($tags,',')) 的 else 分支
即 只保留 if(strstr($tags,',')) 的 true 分支即可

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn