doulu7921 2017-09-03 20:58
浏览 36

mysql_fetch_array只在while循环中显示第1行[duplicate]

I've a stored procedure in mysql db. it took 3 parameters: ID, date_from and date_to. when I run it from my php code, it worked perfectly even if I changed the code every time, BUT when I used it in while loop, it gives my error

mysql_fetch_array() expects parameter 1 to be resource, boolean given

here is the loop:

$IDsRes = mysql_query("select distinct id from mrh_chains order by id;" );
        while($IDs = mysql_fetch_array($IDsRes, MYSQL_BOTH)){
            error_log("ID: ".$IDs[0]);
            $res =  mysql_query("CALL calccommission($chainid,'$startdate','$enddate');");
            $row = mysql_fetch_array($res, MYSQL_BOTH);
            $thefinalres .= "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td><td>".$row[4]."</td><td>".$row[5]."</td></tr>";      
        }
        echo($thefinalres);

and here is the code of stored procedure:

BEGIN

        declare v_totalorderval decimal(18,2);
        declare v_ordercount int;

        declare p_chainname varchar(255);

        declare v_calcedcom decimal(18,2);

        declare v_thechainrefnum int;
        declare v_thechainidincommissionruls int;

        declare v_commissionMethod int;
        declare v_commissionType int;
        declare v_value decimal(18,2);

        declare v_lessThan decimal(18,2); 

        declare v_apply decimal(18,2); 
        DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_apply = 0;
        set v_apply = 0;    

        select comtype into v_commissionType from commissionruls where chainid = p_chainid ;
        select calcmethod into v_commissionMethod from commissionruls where chainid = p_chainid ;

        select refnum into v_thechainrefnum from mrh_chains where id = p_chainid ;

select name into p_chainname from mrh_chains where id = p_chainid ;

select SUM(order_value) into v_totalorderval from mrh_billingstatement where refIds = v_thechainrefnum AND order_date BETWEEN CAST(p_datefrom AS Date) AND CAST(p_dateto AS Date);

select COUNT(order_value) into v_ordercount from mrh_billingstatement where refIds = v_thechainrefnum AND order_date BETWEEN CAST(p_datefrom AS Date) AND CAST(p_dateto AS Date);

    IF(v_commissionMethod = 1) THEN
        select SUM(order_value) into v_value from mrh_billingstatement where refIds = v_thechainrefnum AND order_date BETWEEN CAST(p_datefrom AS Date) AND CAST(p_dateto AS Date);
    END IF;

    IF(v_commissionMethod = 2) THEN
        select COUNT(order_value) into v_value from mrh_billingstatement where refIds = v_thechainrefnum;
    END IF;

        IF(v_commissionType = 1) THEN

            select (fixed * v_value) / 100 into v_calcedcom from commissionruls where chainid = p_chainid;
        END IF;

        IF(v_commissionType = 2) THEN

            select lessthan into v_lessThan from commissionruls where chainid = p_chainid;

            IF(v_value <= v_lessThan) THEN

                select (applylessthan * v_value) / 100 into v_calcedcom from commissionruls where chainid = p_chainid;
            ELSE 

                select (applyelse * v_value) / 100 into v_calcedcom from commissionruls where chainid = p_chainid;
            END IF;
        END IF;

        IF(v_commissionType = 3) THEN

            select id into v_thechainidincommissionruls from commissionruls where chainid = p_chainid;
      select applycalc into v_apply from commissionsteps where commissionrulesid = v_thechainidincommissionruls AND calcto >= v_value AND v_value > calcfrom;

            IF(v_apply > 0) THEN
                select (v_apply * v_value) / 100 into  v_calcedcom;
            ELSE


        select (stepselse * v_value) / 100 into v_calcedcom from commissionruls where chainid = p_chainid;
            END IF;
        END IF;

            select p_chainid, v_thechainrefnum, p_chainname, v_calcedcom, v_ordercount, v_totalorderval;
    END
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ESP8266连接阿里云出现问题
    • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并