日期:2014-05-17  浏览次数:20525 次

mysql怎么一次执行多条SQL语句?
<?php
$sql="
SELECT @a:=id FROM csdn order by id asc limit 30,1;
SELECT @b:=id FROM csdn order by id asc limit 60,1;
SELECT * from csdn where id>@a and id<@b;
";

$result=mysql_query($sql);
while($rs = @mysql_fetch_array($result,MYSQL_ASSOC)){//空记录
echo "<li>".$rs['name'];
}
?>

上面返回空记录。
单独将$sql里面的内容放在phpmyadmin中执行正确,所以SQL语句应该是正确,估计连接方式那城出了问题
请问如何写才能显示出来,谢谢!

------解决方案--------------------
mysql_query不支持同时运行多条SQL。你要以;号拆开分别执行

mysql_query("SELECT @a:=id FROM csdn order by id asc limit 30,1");
mysql_query("SELECT @b:=id FROM csdn order by id asc limit 60,1");
mysql_query("SELECT * from csdn where id>@a and id<@b");