<bdo id='TvFKp'></bdo><ul id='TvFKp'></ul>
  • <small id='TvFKp'></small><noframes id='TvFKp'>

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

        <tfoot id='TvFKp'></tfoot><legend id='TvFKp'><style id='TvFKp'><dir id='TvFKp'><q id='TvFKp'></q></dir></style></legend>

        MYSQLI - 数组中的位置

        时间:2023-07-29
            • <tfoot id='HmCfl'></tfoot>

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

                • <small id='HmCfl'></small><noframes id='HmCfl'>

                  <i id='HmCfl'><tr id='HmCfl'><dt id='HmCfl'><q id='HmCfl'><span id='HmCfl'><b id='HmCfl'><form id='HmCfl'><ins id='HmCfl'></ins><ul id='HmCfl'></ul><sub id='HmCfl'></sub></form><legend id='HmCfl'></legend><bdo id='HmCfl'><pre id='HmCfl'><center id='HmCfl'></center></pre></bdo></b><th id='HmCfl'></th></span></q></dt></tr></i><div id='HmCfl'><tfoot id='HmCfl'></tfoot><dl id='HmCfl'><fieldset id='HmCfl'></fieldset></dl></div>
                    <tbody id='HmCfl'></tbody>
                • 本文介绍了MYSQLI - 数组中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我在互联网上到处寻找有关此问题的答案,然后出现了准备好的语句和绑定参数(我不知道那是什么东西)

                  基本上,我有一个逗号分隔的列表

                  $list = '食物,饮料,烹饪';

                  好的,现在我想在数据库的一列中搜索这些项目中的每一项......听起来很简单,对吧?

                  $query = "SELECT * FROM table WHERE stuff IN ('$list')";$runquery = mysqli_query($connection, $query);while($row = mysqli_fetch_array($runquery,MYSQLI_ASSOC)){$variable = $row;}

                  然后,

                  var_dump($variable);

                  <块引用>

                  未定义变量

                  为什么?我看不出代码有什么问题.如果我输入一个特定的值,它会起作用,并且我已经使用 WHERE stuff=$item 对其进行了测试 - 效果很好.

                  所以不是变量/数据库,而是IN语句中的错误.我不明白为什么它不起作用.

                  解决方案

                  每个元素都需要用引号括起来

                  $list = "'食物', '饮料', '烹饪'";$query = "SELECT * FROM table WHERE stuff IN ($list)";

                  或者如果你有一个数组

                  $array = array("食物","饮料","烹饪");$query = "SELECT * FROM table WHERE stuff IN (".implode(',', $array).")";

                  I've looked all over the internet for answers on this one, and prepared statements and bind params come up (I have no idea what that stuff is)

                  Basically, I have a comma separated list

                  $list = 'food, drink, cooking';
                  

                  Ok, now I want to search for each of those items in a column of the database... Sounds simple, right?

                  $query = "SELECT * FROM table WHERE stuff IN ('$list')";
                  $runquery = mysqli_query($connection, $query);
                  while($row = mysqli_fetch_array($runquery,MYSQLI_ASSOC)){
                      $variable = $row;
                  }
                  

                  Then later on,

                  var_dump($variable);
                  

                  UNDEFINED VARIABLE

                  Why? I can't see anything wrong with the code. It works if I put a particular value, and I have tested it with WHERE stuff=$item - that works fine.

                  So it's not the variables / database, it's an error in the IN statement. I don't understand why it won't work.

                  解决方案

                  Each element needs quotes around it

                  $list = "'food', 'drink', 'cooking'";
                  $query = "SELECT * FROM table WHERE stuff IN ($list)";
                  

                  Or if you had an array

                  $array = array("food","drink","cooking");
                  $query = "SELECT * FROM table WHERE stuff IN (".implode(',', $array).")";
                  

                  这篇关于MYSQLI - 数组中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:单击按钮时更新信息表 下一篇:无法将内爆数组绑定到 mysql 准备好的语句中

                  相关文章

                  最新文章

                • <tfoot id='kh865'></tfoot>
                    <bdo id='kh865'></bdo><ul id='kh865'></ul>

                • <small id='kh865'></small><noframes id='kh865'>

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