。 It has to go on. about how to use an array in PHP as a condition for SQL query statements, my little brother has a problem with my code.

Source: Internet
Author: User
。。。 And then you have to ask for help. I have a problem with my code about how to use arrays as SQL query statements in PHP
There are currently two tables: MHF (meaning models_has_features), MHR (meaning models_has_replacements). One of the MSF fields is model_name and fd_name (meaning feature name), and the MSR field is model_name and rd_name (meaning replacement name).

The user's options for features and replacement are now available through PHP, and they want to search the database using these options to return the model name.

Thanks for the help of the last post, my current relevant code is as follows:

PHP Code
  $usrinput 1=array_merge ($outputs, $functions, $qualifications); Here is the user-entered features option, where each variable is an array and is $usrinput2=array_merge by a multiple-selection list ($ge, $ametek, $weschler, $prime, $VMI, $foxboro, $ Bailey, $chessell, $hays); Here is the user-entered replacement option, where each variable is also an array $query 0= "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 ' "; Among them, $power _input, $display, $case _mounting are string variables that are obtained by a user-selected single-selection list $query 1= "and MHF. Fd_name= ' ". Implode (" ' and Fd_name= ' ", $usrinput 1)." ' "; $query 2= "and MHR. Rd_name= ' ". Implode (" ' and Rd_name= ' ", $usrinput 2)." ' "; $query = $query 0. $query 1. $query 2;//This is to combine the three query into a full query to reach the 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= "Each value in USERINPUT1" and MHR. Rd_name= the effect of "userinput2 values". $result = mysql_query ($query) or Die ("Query failed");


Then it's the output code,
PHP Code
  
   Print "
  
   
   
    
    
   \ 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


But after running no display Ah, I guarantee that my test options should have results, but not show, I hope you guys look at my code where the error, thank you!


------Solution--------------------
In your MHF table, M_name is clearly a sort of
Then, the incoming data
who corresponds to M_name
who corresponds to Fd_name

The conditional expression should be
M_name= ' value ' and fc_name= ' value '

If multiple selections are available, the
M_name in (' Value 1 ', ' Value 2 ', ' Value 3 ' ...) and Fc_name in (' Value 1 ', ' Value 2 ', ' Value 3 ' ...)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.