日期:2014-05-16  浏览次数:21628 次

wwwwb,WWWWA你们看看这个情况
存储过程:
BEGIN
 declare countj int; 
 SELECT COUNT(serverid) INTO countj FROM `count_serverinfo` WHERE gameid = temgameid ORDER BY serverid,days;
BEGIN
  INSERT into daydate(game1,serverorder,serverid,days)
  SELECT game,serverorder,serverid,MAX(IF(days=temdays,amountcount,0.00)) AS days FROM count_serverinfo GROUP BY serverid ORDER BY serverid DESC;
END;
END

php文件中的代码:
$day = $db->query("SELECT days FROM `count_serverinfo` WHERE gameid = '1' GROUP BY days asc ");
foreach($day as $key=>$days){
  $db->getAll("set @temgameid='1',@temdays='".$days['days']."'");
  $sql="call dier(@temgameid,@temdays)";
  $db->getAll($sql);  
}

这个值temdays我在php文件中从一张表里边查询出来了,然后遍历,比如说这个变量有10个值是在存储过程中循环了10次,但是插入到daydate表中的值全都是第一天的数据,为什么啊



------解决方案--------------------
foreach($day as $key=>$days){
$sql="call dier('1','".$days['days']."')";
$db->getAll($sql);
}
------解决方案--------------------
存储过程完整代码,
CREATE PROCEDURE 。。。
在MYSQL中测试,结果如何
------解决方案--------------------
探讨

SET @asql=CONCAT(@asql,'MAX(IF(days=\'',temdays,'\',amountcount,0.00)) AS `',temdays,'`FROM count_serverinfo GROUP BY serverid ORDER BY serverorder DESC');
SELECT @ASQL;
贴结果