Home > Backend Development > PHP Tutorial > 怎么把单个和双个和在一起呀?

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

WBOY
Release: 2016-06-20 12:50:17
Original
1073 people have browsed it

		$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']);	}
Copy after login


回复讨论(解决方案)

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template