我正在尝试使3表标签系统.我在mysql中有3个表:
#文章#
ID
文章
内容
#标签#
tag_id
标签(唯一)
#tagmap#
ID
标签编号
商品编号
在我的提交PHP中,我有:
$tags= explode(',', strtolower($_POST['insert_tags']));
for ($x = 0; $x < count($tags); $x++) {
//Add new tag if not exist
$queryt = "INSERT INTO `tags` (`tag_id`, `tag`) VALUES ('', '$tags[x]')";
$maket = mysql_query($queryt);
//Add the relational Link, now this is not working, beacasue this is only draft
$querytm = "INSERT INTO `tagmap` (`id`, `tagid`, `articleid`) VALUES ('', (SELECT `tag_id` FROM `tags` WHERE tag_id = "$tags[x]"), '$articleid')";
$maketm = mysql_query($querytm);
}
当我向文章提交新标签时,这不起作用. Mysql不在我的标签表中创建新标签.
PS.对不起,英语不好.
解决方法:
您缺少’x’变量的$符号.尝试对两行都这样.
'" . $tags[$x] . "'
我也建议采用这种方式,无需使您的SQL查询复杂化.
$tags= explode(',', strtolower($_POST['insert_tags']));
for ($x = 0; $x < count($tags); $x++) {
//Add new tag if not exist
$queryt = "INSERT INTO `tags` (`tag_id`, `tag`) VALUES ('', '" . $tags[$x] . "')";
$maket = mysql_query($queryt);
//Get tag id
$tag_id = mysql_insert_id();
//Add the relational Link, now this is not working, beacasue this is only draft
$querytm = "INSERT INTO `tagmap` (`id`, `tagid`, `articleid`) VALUES ('', '$tag_id', '$articleid')";
$maketm = mysql_query($querytm);
}
标签:mysql,php,insert,tags 来源: https://codeday.me/bug/20191202/2085402.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。