<small id='xKzTn'></small><noframes id='xKzTn'>

    <i id='xKzTn'><tr id='xKzTn'><dt id='xKzTn'><q id='xKzTn'><span id='xKzTn'><b id='xKzTn'><form id='xKzTn'><ins id='xKzTn'></ins><ul id='xKzTn'></ul><sub id='xKzTn'></sub></form><legend id='xKzTn'></legend><bdo id='xKzTn'><pre id='xKzTn'><center id='xKzTn'></center></pre></bdo></b><th id='xKzTn'></th></span></q></dt></tr></i><div id='xKzTn'><tfoot id='xKzTn'></tfoot><dl id='xKzTn'><fieldset id='xKzTn'></fieldset></dl></div>

    <tfoot id='xKzTn'></tfoot>
        <bdo id='xKzTn'></bdo><ul id='xKzTn'></ul>
      <legend id='xKzTn'><style id='xKzTn'><dir id='xKzTn'><q id='xKzTn'></q></dir></style></legend>

      MySQL select where 等于多个值

      MySQL select where equal to multiple values(MySQL select where 等于多个值)
      • <legend id='ASzf5'><style id='ASzf5'><dir id='ASzf5'><q id='ASzf5'></q></dir></style></legend>
        • <bdo id='ASzf5'></bdo><ul id='ASzf5'></ul>
            <tbody id='ASzf5'></tbody>

            <tfoot id='ASzf5'></tfoot>
          1. <i id='ASzf5'><tr id='ASzf5'><dt id='ASzf5'><q id='ASzf5'><span id='ASzf5'><b id='ASzf5'><form id='ASzf5'><ins id='ASzf5'></ins><ul id='ASzf5'></ul><sub id='ASzf5'></sub></form><legend id='ASzf5'></legend><bdo id='ASzf5'><pre id='ASzf5'><center id='ASzf5'></center></pre></bdo></b><th id='ASzf5'></th></span></q></dt></tr></i><div id='ASzf5'><tfoot id='ASzf5'></tfoot><dl id='ASzf5'><fieldset id='ASzf5'></fieldset></dl></div>

            <small id='ASzf5'></small><noframes id='ASzf5'>

              • 本文介绍了MySQL select where 等于多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有两个数据库,我存储谁在关注谁,另一个存储用户发布的帖子.

                I have two databases, where I store who is following who and another which stores the posts the user makes.

                我想从以下数据库中选择用户关注的所有人,并回显出该用户关注的用户的用户名,并在帖子数据库中查询该用户的帖子.

                I want to select all of the people a user is following from the following database and echo out the usernames of those who that user is following and query the posts database for posts of that user.

                我的问题是如果一个用户关注多个用户怎么办,我从该用户所关注的人的用户 ID 中回显出来,然后我得到了44443344330

                My problem is what if a user is following multiple users, I echoed out of the user id's of the people this user is following and I get 44443344330

                当我用逗号分隔每个 id 时,我得到:

                When I separate each id with commans, I get:

                44,44,33,44,33,0, 
                

                所以让我们给它一个变量 $user_ids;

                so let's give that a variable of $user_ids;

                $user_ids = "44,44,33,44,33,0, ";
                

                查询:

                $get_posts = mysql_query("SELECT * FROM posts WHERE userid = '$user_ids'");
                

                但它所做的只是显示第一个用户 ID 44 的记录.

                but all it does is show the records of the first user id, 44.

                如何检索所有用户的所有记录?

                How can I retrieve all of the records for all the users?

                推荐答案

                查询应该是:

                SELECT * FROM posts WHERE userid IN (44,44,33,44,33,0)
                

                但是,您可能需要重新考虑您的数据模型并确保它是规范化的,以便您可以直接在数据库中表达这种结构,而无需回显到逗号分隔的字符串中.

                However, you may have to rethink your data model and make sure it is normalized, so that you can express this construction directly in the databse without echoing into a comma-separated string.

                为什么你有两个数据库?你的意思是两个?

                Why do you have two databases? Do you mean two tables?

                这篇关于MySQL select where 等于多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Building a comma separated list?(建立一个逗号分隔的列表?)
                Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                How to update a record using sequelize for node?(如何使用节点的 sequelize 更新记录?)
                How to provide a mysql database connection in single file in nodejs(如何在 nodejs 中的单个文件中提供 mysql 数据库连接)
                Defining a one-to-one relationship in SQL Server(在 SQL Server 中定义一对一关系)
                Looping Over Result Sets in MySQL(在 MySQL 中循环结果集)

                <small id='JZvCs'></small><noframes id='JZvCs'>

                    <tfoot id='JZvCs'></tfoot>
                      • <bdo id='JZvCs'></bdo><ul id='JZvCs'></ul>
                          <tbody id='JZvCs'></tbody>
                        <legend id='JZvCs'><style id='JZvCs'><dir id='JZvCs'><q id='JZvCs'></q></dir></style></legend>
                        • <i id='JZvCs'><tr id='JZvCs'><dt id='JZvCs'><q id='JZvCs'><span id='JZvCs'><b id='JZvCs'><form id='JZvCs'><ins id='JZvCs'></ins><ul id='JZvCs'></ul><sub id='JZvCs'></sub></form><legend id='JZvCs'></legend><bdo id='JZvCs'><pre id='JZvCs'><center id='JZvCs'></center></pre></bdo></b><th id='JZvCs'></th></span></q></dt></tr></i><div id='JZvCs'><tfoot id='JZvCs'></tfoot><dl id='JZvCs'><fieldset id='JZvCs'></fieldset></dl></div>