mysql SET类型和多数据进程用php在sql查询中(Mysql SET type and multi data process with php in sql query)
所以我一直在尝试在我的网站上创建一个搜索表单,这取决于用户检查的内容(复选框),我花了很多时间在网上研究,但没有找到任何东西,所以我不得不自己做。 所以这里是html的代码
<li><input type="checkbox" name="checkbox[]" value="action"> Action</li> <li><input type="checkbox" name="checkbox[]" value="Adventure"> Adventure</li> <li><input type="checkbox" name="checkbox[]" value="Animation"> Animation</li> <li><input type="checkbox" name="checkbox[]" value="cars"> Cars</li> <li><input type="checkbox" name="checkbox[]" value="cartoon"> Cartoon</li> <li><input type="checkbox" name="checkbox[]" value="comedy"> Comedy</li>
这是php
<?php if(!empty($_POST['checkbox'])) { $Gen3 = implode(" AND * ", $_POST['checkbox']); $Gen2= str_replace('*', 'Genre like ', $Gen3); $table='animelist'; $sql = "SELECT * FROM $table WHERE Genre like '".$Gen2."' ORDER BY NAME DESC" ; echo $sql; $result = mysqli_query($conn, $sql) or die('Erreur SQL !'.$req.'<br>'.mysql_error()); while($row = $result->fetch_assoc()){ ?> <li><a href="Anime.php?/anime=<?php echo $row['Name']; ?>"><?php echo $row['Name']; ?></a></li> <?php ; } }; ?>
echo $ sql如果我检查两个复选框,例如结果
SELECT * FROM animelist WHERE Genre like 'action AND Genre like Adventure' ORDER BY NAME DESC
所以这里的事情是用户研究的“电影”可能是“动作,冒险”的一套,所以当用户选中复选框时,结果必须是“电影”,这不仅仅是动作和冒险行动。
现在,如果我只检查一个复选框,evrything工作正常,但当我检查两个或更多时,我什么都没得到
所以我虽然在变量之前和之后的sql查询是破坏它的那个,所以我不得不骑它们,所以我尝试使用mysql_real_escape_string,但是因为它不再是受理者而且mysqli_real_escape_string不做我被困在这里的工作。
So I've been trying to create a search form on my website that depends on what the user check ( checkboxes), I've spent many time researching on web but didn't find anything, so I had to do things myself. so here is the code for the html
<li><input type="checkbox" name="checkbox[]" value="action"> Action</li> <li><input type="checkbox" name="checkbox[]" value="Adventure"> Adventure</li> <li><input type="checkbox" name="checkbox[]" value="Animation"> Animation</li> <li><input type="checkbox" name="checkbox[]" value="cars"> Cars</li> <li><input type="checkbox" name="checkbox[]" value="cartoon"> Cartoon</li> <li><input type="checkbox" name="checkbox[]" value="comedy"> Comedy</li>
and here is the php
<?php if(!empty($_POST['checkbox'])) { $Gen3 = implode(" AND * ", $_POST['checkbox']); $Gen2= str_replace('*', 'Genre like ', $Gen3); $table='animelist'; $sql = "SELECT * FROM $table WHERE Genre like '".$Gen2."' ORDER BY NAME DESC" ; echo $sql; $result = mysqli_query($conn, $sql) or die('Erreur SQL !'.$req.'<br>'.mysql_error()); while($row = $result->fetch_assoc()){ ?> <li><a href="Anime.php?/anime=<?php echo $row['Name']; ?>"><?php echo $row['Name']; ?></a></li> <?php ; } }; ?>
the echo $sql if I check two checkboxes for example result
SELECT * FROM animelist WHERE Genre like 'action AND Genre like Adventure' ORDER BY NAME DESC
so the thing here is that the "movie" that the user would research might be a SET of "Action,Adventure" , so when the user checks the checkboxes the result have to be the "movies" which are both Action and adventure not only Action.
for now if I only check one checkbox evrything works fine but when I check two or more I get nothing
so I though that the ' in the sql query before and after the variable are the one ruining it, so I had to get ride of them, so I tried to use mysql_real_escape_string, but since its not accepter anymore and the mysqli_real_escape_string doesn't do the job I am stuck here.
原文:https://stackoverflow.com/questions/33979888
满意答案
有许多集合支持这一点。 例如,jME3使用自己的ArrayList变体,称为
SafeArrayList
。 这是一个开源项目,所以你可以在那里找到实现。比每次读取克隆更好的解决方案是在修改时复制列表。 只需创建一个新列表,对其进行更改,然后将其分配回您的侦听器列表。
在大多数情况下,观察者的变化发生在循环观察者身上的次数较少。
如果您复制列表并修改克隆,那么迭代上一版本列表的任何内容都不会看到更改,但也不会例外。
There are a number of collections that support this. For example jME3 uses their own variant of ArrayList called
SafeArrayList
. It's an open source project so you can find the implementation there.A better solution than cloning on every read is to copy the list on modification. Just create a new list, make the change to it, assign that back to your list of listeners.
In most cases changes to observers happens less often that looping over observers.
If you copy the list and modify the clone then anything iterating over the previous version of the list will not see the change but will also not exception.
相关问答
更多MVP中的观察者模式(Observer Pattern in MVP)
观察者模式的策略?(strategy for observer pattern?)
我的代码中的javascript观察者模式帮助(javascript observer pattern help in my code)
C#中的观察者模式/如何使表单成为观察者(Observer pattern in C# / how to make a Form an observer)
观察者设计模式(Observer Design Pattern)
MVVM本身是Observer模式吗?(Is MVVM itself a Observer pattern?)
事件处理和观察者模式(GoF)(Event handling and Observer pattern (GoF))
避免观察者模式中的并发修改(Avoiding concurrent modification in observer pattern)
为什么我们需要观察者模式?(Why do we need the Observer pattern?)
观察者和一个主题的模式(Pattern for observer and one subject)
相关文章
更多Becoming a data scientist
multi-core solr deploy process(not complete)
my php & mysql FAQ
multi-core solr deploy process(not complete)
7月最新发布11.2.0.1.2 Patch set update
《Big Data Glossary》笔记
Mysql错误:Ignoring query to other database解决方法
关于mysql 的 sql
MongoDB学习 (五):查询操作符(Query Operators).1st
(二)solr data import
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!