我试图将 php mysql_fetch_row 结果转换为 javascript 数组,所以我写下面的代码来做到这一点。但我遇到了问题,如果结果中有多行,那么只有最后一行存储在 javascript 数组中
<script>
function sub()
{
alert("coming");
var a= new Array;
<?php
$dbhost ='localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'pupilcafe';
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error Connecting to mysql');
mysql_select_db($dbname,$conn);
$uid=1;
$semester='1stSemester';
$cid=1;
$qry="select * from subject where cid='$cid'&& uid='$uid'&& semester='$semester'";
$res = mysql_query($qry);
while($data=mysql_fetch_row($res))
{
$i=0;
echo "a[$i]='".$data[1]."';";
$i++;
}
?>
alert(a[0]);
}
</script>
所以这里mysql代码获取两行frm db(Englishphp)但结果我只有php ..我想要javascript数组中的这两行所以怎么做?