在发布主题/回复时增加用户帖子计数
我对 SQL 很陌生,在网上寻找有关增加值的帮助,但找不到适合我的东西。我想做的是在发布回复/主题时增加 user_posts 的值。 user_posts位于用户中(论坛>用户>用户帖子)。我不知道如何获取特定用户,然后添加他/她的帖子的价值。我正在研究一个非常小且基本的示例,这就是我发布帖子的方式。我想我可以将它添加到将主题发送到数据库的 SQL 中,但是,就像我说的,不知道如何做。我真的没有任何代码可以开始,因为我真的不知道从哪里开始。我相信它使用 UPDATE,但这就是我所能猜测的。如果您在阅读完所有内容后仍不太确定我想要什么,请询问,我会尽力澄清。
这是部分工作后代码和似乎不起作用的建议代码的样子。
VALUES ('" . $_POST['reply-content'] . "',
NOW(),
" . mysql_real_escape_string($_GET['id']) . ",
" . $_SESSION['user_id'] . ");
UPDATE users SET user_posts=1 WHERE user_id=1";
I'm really new to SQL and looked around the web for help on incrementing values but couldn't find something that works for me. What I'm trying to do is increment the value of user_posts when a reply/topic is posted. The user_posts is in users (forums>users>user_posts). I don't know how to get the specific user and then add to the value of his/her posts. I'm working off of a very small and basic example, which is how I have posts working. I was thinking I could add it to the SQL where the topic is sent to the DB but, like I said, can't figure out how. I don't really have any code to provide to start with because I really don't know where to start. I believe it uses UPDATE, but that's all I can guess. If you aren't quite sure what it is I want even after reading all of this, ask and I'll try to clarify.
Here's what it looks like with part of the working post code and a suggested code that doesn't seem to work.
VALUES ('" . $_POST['reply-content'] . "',
NOW(),
" . mysql_real_escape_string($_GET['id']) . ",
" . $_SESSION['user_id'] . ");
UPDATE users SET user_posts=1 WHERE user_id=1";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以写
You can write
类似于:
select postcount from users where user_id =;
其次是update users set postcount=;其中 user_id =;
。一些详细信息: http://www.w3schools.com/sql/sql_update.asp我除非您在处理负载时遇到问题,否则不会担心优化对数据库的查询。 :)
Something like:
select postcount from users where user_id = <userid>;
followed byupdate users set postcount=<new_postcount> where user_id = <userid>;
. Some details: http://www.w3schools.com/sql/sql_update.aspI wouldn't worry about optimizing your queries to your database until you experience problems handling your load. :)