douwen3500 2012-08-02 04:14 采纳率: 0%
浏览 40
已采纳

这是MYSQL还是PHP错误? 当mysql_fetch_array时

I have an error like this :

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\lab\try.php on line 40

The query is :

$graphquery = mysql_query ("SELECT
  $cluster,
  SUM(IF(idx=3,1,0)) AS green,
  SUM(IF(idx=2,1,0)) AS yellow,
  SUM(IF(idx=1,1,0)) AS red
FROM (SELECT
        $cluster
        $xcond
        ,LEAST(999 $acond) idx 
      FROM table
      WHERE date >= '". $startDate ."'
          AND date <= '". $endDate ."'
          AND $regional = '$gregcond'
          AND $latitude IS NOT NULL 
      GROUP BY $cluster, $lac, $mainid
      HAVING $cluster IS NOT NULL
$paraxcond
      ) A
GROUP BY $cluster");

If I echo the query, it will be like this (no error, perfect result too btw) :

SELECT
  cluster,
  SUM(IF(idx=3,1,0)) AS green,
  SUM(IF(idx=2,1,0)) AS yellow,
  SUM(IF(idx=1,1,0)) AS red
FROM (SELECT
        cluster,
        ROUND(AVG(some_value_Index))    some_value_Index,
        LEAST(999, AVG(some_value_Index) )    idx
      FROM TABLE
      WHERE tanggal >= '2012-07-10'
          AND tanggal <= '2012-08-02'
          AND Regional = 'Regional_Example'
          AND Latitude IS NOT NULL
      GROUP BY cluster, Lac, ID
      HAVING cluster IS NOT NULL
          AND some_value_Index IN(3,2,1)) A
GROUP BY cluster

When I add mysql_error on that script, it sounds like this :

Incorrect parameter count in the call to native function 'LEAST'

And here is how I willing to use the MYSQL Query :

$row = mysql_fetch_array ($graphquery)

When I am ECHO the query and try it on SQLYOG or PHPMYADMIN there is no error contained, so Can anyone tell me where is the error please?

  • 写回答

1条回答 默认 最新

  • dongmoxin7111 2012-08-02 04:25
    关注

    You missed a comma in the LEAST() function. LEAST expects 2 or more parameters. So the query will be.

    mysql_query ("SELECT
      $cluster,
      SUM(IF(idx=3,1,0)) AS green,
      SUM(IF(idx=2,1,0)) AS yellow,
      SUM(IF(idx=1,1,0)) AS red
    FROM (SELECT
            $cluster
            $xcond
            ,LEAST(999, $acond) idx 
          FROM table
          WHERE date >= '". $startDate ."'
              AND date <= '". $endDate ."'
              AND $regional = '$gregcond'
              AND $latitude IS NOT NULL 
          GROUP BY $cluster, $lac, $mainid
          HAVING $cluster IS NOT NULL
    $paraxcond
          ) A
    GROUP BY $cluster");
    

    I changed LEAST(999 $acond) to LEAST(999, $acond)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制