我在mysql db中有一个存储过程。它花了3个参数:ID,date_from和date_to。当我从我的php代码运行它时,即使我每次都更改代码,它也能完美运行,但是当我在while循环中使用它时,它会给出我的错误
mysql_fetch_array()期望参数1为资源,布尔值为
这是循环:
$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);
这是存储过程的代码:
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