English 中文(简体)
如何使用两个以上“WHERE”条款? MYSQL ERROR
原标题:How to use more than two "WHERE" clause? MYSQL ERROR

I am using it to do with PHP.

ERROR:-

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near at line 1

http://www.ohchr.org。

$SQLQUERY = sprintf("SELECT pd_serial FROM product_details WHERE pd_model_type=%s AND pd_model_name=%s AND pd_model_version=%s AND pd_product_group=%s LIMIT 1",
GetSQLValueString($modeltype, "text"),
GetSQLValueString($modelname, "text"),
GetSQLValueString($modelversion, "text"),
GetSQLValueString($modelgroup, "text"));
$QUERYEXEC =  mysql_query($SQLQUERY, $dacreint) or die("OOPS! Please try again.");

while ($QUERYFETCH = mysql_fetch_array($QUERYEXEC))
{
    $pdserial = $QUERYFETCH[ pd_serial ];
}

<><><><>>>>

while ($QUERYFETCH = mysql_fetch_array($QUERYEXEC))
{
    $pdserial = $QUERYFETCH[ pd_serial ];
}
$SQLQUERY = sprintf("SELECT product_serial_no FROM products WHERE product_serial_no =  $product_serial_no ");
$TCcount_QE = mysql_query($SQLQUERY, $dacreint) or die(mysql_error());
最佳回答

You should put strings within single quotes. And make sure you have escaped those string values using mysql_real_escape_string() or similar function

SELECT pd_serial FROM product_details WHERE (pd_model_type= %s  AND pd_model_name= %s ) AND (pd_model_version= %s  AND pd_model_group= %s ) LIMIT 1

<>12>

            while ($QUERYFETCH = mysql_fetch_array($QUERYEXEC))
            {
                $pdserial = $QUERYFETCH[ pd_serial ];
            }
    // let s comment out the following line
        //    $SQLQUERY = sprintf("SELECT product_serial_no FROM products WHERE product_serial_no =  $product_serial_no ");
// and modifying it as:
            $SQLQUERY = sprintf("SELECT product_serial_no FROM products WHERE product_serial_no = %s", GetSQLValueString($product_serial_no, "text"));
            $TCcount_QE = mysql_query($SQLQUERY, $dacreint) or die(mysql_error());
问题回答

请补充“提出”问题吗? 你们的参数是否应当包含在引用的“%”中?

顺便说一句:你不必把母子放在一个完全与“任务”挂钩的WHERE-statement中。

这里是正确的。

SELECT pd_serial FROM product_details WHERE pd_model_type=%s AND pd_model_name=%s AND pd_model_version=%s AND pd_model_group=%s LIMIT 1

Edited

SELECT pd_serial FROM product_details WHERE pd_model_type like  %s  AND pd_model_name like  %s  AND pd_model_version like  %s  AND pd_model_group like  %s  LIMIT 1

由于我们在这里使用野生卡,因此Sorry i 想像在括号中那样附上条件,而我就失踪了。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签