在 php 和 mysql 中标记
我用于添加标签的数据库架构与这个问题相同...
我的问题是如何将每个标签与当前线程相关联,到目前为止我已经这样做了:
$sql = "INSERT INTO thread (title, content, author_id)
VALUES ('$safe_title', '$safe_html_content', '$user_id')";
$insert_thread = insert_Query($sql, $link);
# get the thread id:
$thread_id = mysqli_insert_id($link);
# insert the tags:
foreach ($tags as $tag)
{
insert_Query("INSERT INTO tags (tag)
VALUES ('$tag')", $link);
}
# connect tags to thread:
$sql = "INSERT INTO thread_tags (thread_id, tag_id)
VALUES ('$thread_id', )"; ## what to do here?
我想知道如何填写 ItemTag 表(在我的情况下是 thread_tags )...我可以获得 id当前线程的 ID,如 $thread_id var 中所示,但是如何获取每个标记的 id 并将其与该线程关联?
谢谢。
My database schema for adding tags is the same as this question...
My question is how do I relate each tag with the current thread, so far I have done this:
$sql = "INSERT INTO thread (title, content, author_id)
VALUES ('$safe_title', '$safe_html_content', '$user_id')";
$insert_thread = insert_Query($sql, $link);
# get the thread id:
$thread_id = mysqli_insert_id($link);
# insert the tags:
foreach ($tags as $tag)
{
insert_Query("INSERT INTO tags (tag)
VALUES ('$tag')", $link);
}
# connect tags to thread:
$sql = "INSERT INTO thread_tags (thread_id, tag_id)
VALUES ('$thread_id', )"; ## what to do here?
I want to know how I can fill in the ItemTag table (thread_tags in my case)... I can get the id of the current thread as shown in the $thread_id var, but how do I get the id of each tag and associate it with this thread?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定你为什么要这样做,但你尝试过吗?
I'm not really sure why do you want to do it like that, but did you try this?