. You have to continue. Concerning how to use arrays as the conditions for SQL query statements in PHP, I have some questions about the code.

Source: Internet
Author: User
... You have to ask for help .. My code has a problem with how PHP uses arrays as the conditions for SQL query statements. Currently, there are two tables: mhf (models_has_features) and mhr (models_has_replacements ). here, msf fields are Model_Name and FD_Name (meaning FeatureName), and msr fields are Model_Name and RD_Nam... You have to ask for help .. My code has a problem about how PHP uses arrays as the conditions for SQL query statements.
Currently, there are two tables: mhf (models_has_features) and mhr (models_has_replacements ). here, msf fields are Model_Name and FD_Name (meaning Feature Name), and msr fields are Model_Name and RD_Name (meaning Replacement Name ).

Now, you can use php to obtain the features and replacement options. you want to use these options for database search and then return the model name.

Thanks to the help of the moderator in the previous post, my current code is as follows:

PHP code
  $ Usrinput1 = array_merge ($ outputs, $ functions, $ qualifications); // Here is the features option entered by the user, where each variable is an array, from the multi-choice list $ usrinput2 = array_merge ($ ge, $ ametek, $ weschler, $ prime, $ vmi, $ foxboro, $ bailey, $ chessell, $ hays ); // Here is the replacement option entered by the user, where each variable is also an array $ 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' "; // where $ power_input, $ display, $ case_mounting are string variables, which are obtained from the selected radio list $ query1 =" AND mhf. FD_Name = '". implode ("'AND FD_Name ='", $ usrinput1 ). "'"; $ query2 = "AND mhr. RD_Name = '". implode ("'AND RD_Name ='", $ usrinput2 ). "'"; $ query = $ query0. $ query1. $ query2; // Here we want to combine these three queries into a complete query to achieve select SELECT mhf. m_Name FROM mhf, mhr WHERE mhf. m_Name = mhr. m_Name AND mhf. FD_Name = '$ input_signal '... AND mh F. FD_Name = "userinput1 values" AND mhr. RD_Name = "userinput2 values. $ Result = mysql_query ($ query) or die ("Query failed ");


Then the code is output,
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
\n";


However, no display is displayed after running. I promise that my test options should have results, but they cannot be displayed. I hope you can see what went wrong with my code. thank you!


------ Solution --------------------
In your mhf table, M_Name is obviously a classification.
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 you can select multiple, it is
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.