怎么把单个和双个和在一起呀?
程序员文章站
2022-06-14 18:57:58
...
$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 分支即可
推荐阅读