。还得接着。关于PHP中怎么把数组作为sql查询语句的条件,小弟我的代码有有关问题

WBOY
Release: 2016-06-13 13:41:14
Original
830 people have browsed it

。。。还得接着求助。。关于PHP中如何把数组作为sql查询语句的条件,我的代码有问题
目前有两张表:mhf (意为models_has_features), mhr(意为models_has_replacements). 其中msf的字段为Model_Name和FD_Name(意为Feature Name),msr的字段为Model_Name和RD_Name(意为Replacement Name). 

现在通过php获取了用户对于features 和 replacement的选项,想通过这些选项进行数据库搜索,从而返回model名称。

感谢上个帖子版友的帮助,我目前的相关代码如下:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$usrinput1=array_merge($outputs,$functions,$qualifications); //这里是用户输入的features选项,其中各个变量均是数组,由多选列表而来
$usrinput2=array_merge($ge,$ametek,$weschler,$prime,$vmi,$foxboro,$bailey,$chessell,$hays); //这里是用户输入的replacement选项,其中各个变量也均是数组

 $query0="SELECT mhf.M_Name FROM mhf,mhr 
          WHERE mhf.M_Name=mhr.M_Name 
          AND mhf.FD_Name='$input_signal' 
          AND mhf.FD_Name='$power_input' 
          AND mhf.FD_Name='$display' 
          AND mhf.FD_Name='$case_mounting'";
 //其中,$power_input,$display,$case_mounting 均是字符串变量,是由用户选择的单选列表获取而来

 $query1="AND mhf.FD_Name='".implode("' AND FD_Name='",$usrinput1)."'";
 $query2="AND mhr.RD_Name='".implode("' AND RD_Name='",$usrinput2)."'";

 $query=$query0.$query1.$query2;

//这里是想把这三个query组合成一个完整的query,从而达到 select SELECT mhf.M_Name FROM mhf,mhr  WHERE mhf.M_Name=mhr.M_Name  AND mhf.FD_Name='$input_signal'... AND mhf.FD_Name="userinput1里各个值" AND mhr.RD_Name="userinput2里各个值" 的效果。

 $result = mysql_query($query) or die("Query failed"); 
 

Copy after login


然后就是输出代码,
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
 print "
Copy after login
\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { print "\t\n"; foreach ($line as $col_value) { print "\t\t\n"; } print "\t\n"; } print "
$col_value
\n";


可是运行了之后没有任何显示啊,我保证自己的测试选项是应该有结果的,可是显示不出来,希望各位高人看看我的代码哪里出错了,多谢!


------解决方案--------------------
在你的 mhf 表中,M_Name 显然是个分类
那么,传入的数据
谁对应 M_Name
谁对应 FD_Name

条件表达式应为
M_Name='值' AND FC_Name='值'

如果可以多选,则为
M_Name in('值1','值2','值3'...) AND FC_Name in('值1','值2','值3'...)
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template