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
2021-12-30 19:12

满意答案

有许多集合支持这一点。 例如,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)

没关系。 你有一个对象, Presenter ,它在一个线程内的无限循环中使用。 这并不意味着你也不能在线程调用它时调用它的方法。 您需要注意的唯一考虑因素是,如果线程读取/使用的数据与观察者通知相同,则您应该同步它的访问权限。 因此,总而言之,当Presenter在无限循环内运行时,对它的方法的任何调用都将立即得到解答(除非它们具有同步访问权限,在这种情况下它将阻塞直到获得锁定所有权) 以下是完全正常的: class Presenter implements IObserver { pu...

观察者模式的策略?(strategy for observer pattern?)

在支持多重继承的语言中,支持这种功能的对象来自支持这些方法的Observable类的INHERIT并不罕见。 我从来没有遇到过使用聚合来支持这个的解决方案,这就是你所描述的,但鉴于PHP不支持多重继承,这听起来像是一个合理的解决方法。 It's not unusual for an object that supports this functionality to INHERIT from an Observable class, which supports these methods, in...

我的代码中的javascript观察者模式帮助(javascript observer pattern help in my code)

要小心,在创建新对象时, new Subject()会有一个提供新对象的隐式return 。 您不需要像往常一样返回对象。 现在,对于方法,您需要将它们附加到对象的原型 。 这样,当创建对象时, 它将附加这些方法 。 例如: function MySuperObject( value ) { this.property = value; }; MySuperObject.prototype.attachedMethod = function() { console.log("Pr...

C#中的观察者模式/如何使表单成为观察者(Observer pattern in C# / how to make a Form an observer)

简答:看看这个问题的第一个答案: 带代表的C#观察者/观察者的超简单例子 我理解你想尝试自己实现它,但委托和事件在这里真的很合适(实际上是c#中内置的观察者模式的实现)。 如果仍想自己做,我建议使用接口而不是抽象/具体类。 public interface ISubject { void AttachObserver(IObserver observer); void DetachObserver(IObserver observer); void NotifyObser...

观察者设计模式(Observer Design Pattern)

经典的设计模式不涉及并行和线程。 你必须为N个观察者产生N个线程。 但要小心,因为它们之间的交互必须以线程安全的方式完成。 Classic design patterns do not involve parallelism and threading. You'd have to spawn N threads for the N observers. Be careful though since their interaction to this will have to be done i...

MVVM本身是Observer模式吗?(Is MVVM itself a Observer pattern?)

MVVM-和Observable-模式是不同的模式,你会发现很多很好的例子。 假设您正在实施MVVM电话应用程序,这两种模式可以很好地结合使用: 您的ViewModel(MV VM )具有要在XAML-VIEW(M V VM)中显示/更新的属性。 无论何时设置(或更新)属性值(在ViewModel中),都会触发类似()=> PropertyChanged("PropertyName); Observer现在位于MVVM Framework(或ViewModel的基类)中,此组件观察这些更改并使用V...

事件处理和观察者模式(GoF)(Event handling and Observer pattern (GoF))

你的问题是比较苹果和梨。 观察者模式是问题的解决方案。 它没有告诉你如何实现解决方案,但更像是蓝图。 因此,.NET中的事件模型是观察者模式的实现。 EventHandler委托定义观察者, event关键字负责处理主题中的所有通知,正如观察者模式中所定义的那样。 Your question is comparing apples and pears. The observer pattern is a solution to a problem. It doesn't tell you how ...

避免观察者模式中的并发修改(Avoiding concurrent modification in observer pattern)

有许多集合支持这一点。 例如,jME3使用自己的ArrayList变体,称为SafeArrayList 。 这是一个开源项目,所以你可以在那里找到实现。 比每次读取克隆更好的解决方案是在修改时复制列表。 只需创建一个新列表,对其进行更改,然后将其分配回您的侦听器列表。 在大多数情况下,观察者的变化发生在循环观察者身上的次数较少。 如果您复制列表并修改克隆,那么迭代上一版本列表的任何内容都不会看到更改,但也不会例外。 There are a number of collections that su...

为什么我们需要观察者模式?(Why do we need the Observer pattern?)

简单的说,让你了解观察者模式 如果1000人订阅每日新闻报纸。 每当新副本到达时,即每天,发布者都会向其订阅者发送一份副本。 同样的方法一个类在获取新信息时就会向其观察者发送信息。 in Simple words ,to make you understand Observer pattern if 1000 people are subscribed to a daily news paper. Publisher will send a copy to his subscribers when...

观察者和一个主题的模式(Pattern for observer and one subject)

观察者模式仍然适合。 但是模式不是一成不变的,如果你不需要一组观察者,你可以简化一下:实现观察者 - >主题关联为1:1 The observer pattern still suits. But patterns are not set in stone, you can simplify it a bit if you don't need a collection of observers: implement the observer-->subject association as 1:...

相关文章

更多

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

multi-core solr deploy process(not complete)

根据/etc/tomcat6/Catalina/localhost/solr.xml中部署的solr. ...

my php & mysql FAQ

php中文字符串长度及定长截取问题使用str_len(&quot;中国&quot;) 结果为6,php ...

multi-core solr deploy process(not complete)

How to set up Solr on Ubuntu 10.04 (or whatever) 0 ...

7月最新发布11.2.0.1.2 Patch set update

7月13日,11g release 2 的第二个补丁集更新发布了;9i的最终版本为9.2.0.8,10 ...

《Big Data Glossary》笔记

清明假期翻以前的笔记发现有一些NoSQL相关的内容,比较零散,是之前读《Big Data Glossa ...

Mysql错误:Ignoring query to other database解决方法

用source c:\xxx.sql,出现Ignoring query to other databa ...

关于mysql 的 sql

有两张表如下: a表: id name A a B b b表: cid cname 1 ...

MongoDB学习 (五):查询操作符(Query Operators).1st

查询操作符(Query Operators)可以让我们写出复杂查询条件,让我们使用的过程更加灵活。官方 ...

(二)solr data import

solr 的 data import 导入 mysql数据 (1)、编辑 example/solr/c ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本