-8

我在 MYSQL 中遇到错误

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

有人可以向我解释这个错误是怎么回事吗?谢谢。

PHP代码:

<?php

$link = connectToDB();
 $strXML = "<chart caption='Factory Output report' subCaption='By Quantity' pieSliceDepth='30' showBorder='1' formatNumberScale='0' numberSuffix=' Units'>";




    $result = mysqli_query($link, "SELECT DISTINCT PROFILE FROM tbljocreator GROUP BY PROFILE");
    $show = mysqli_fetch_array($result);
    if($result) {
    while ($ors = mysqli_fetch_array($result)) {

    $strQuery = "select PROFILE, sum(MT) as totalLM from tbljocreator where PROFILE =" .$ors['PROFILE'];
    $result2 = mysqli_query($link, $strQuery) or die(mysqli_error($link));
    $getresult2 = mysqli_fetch_array($result2); 


    $strXML .= "<set label='" . $ors['profile'] . "' value ='" . $getresult2['totalLM'] . "' />";


    mysqli_free_result($result2);
    }
    }
    mysqli_close($link);
    $strXML .= "</chart>";

        echo renderChart("FusionCharts/Column3D.swf", "", $strXML, "JoCreator", 450, 300, false, true);

    ?>

请为我解释清楚。

4

1 回答 1

0

听起来像是$ors['PROFILE']一个空变量。在某处做一个print_r($ors)并将您的查询更改为,$strQuery = "select PROFILE, sum(MT) as totalLM from tbljocreator where PROFILE = '" .$ors['PROFILE']."'";以便下次不会抛出该错误。

顺便说一下,作为解释,错误是因为如果变量为空,则查询在=. 由于它在这里需要一个参数,所以它抛出了错误。由于错误仅显示问题的最开始,即查询的最后,因此它是一个空字符串。(靠近 '')

于 2013-11-11T04:55:47.253 回答