i m trying to convert php mysql_fetch_row result into javascript array so i write below code to do that. but i got problem , if there are multiple row in result, then only last row stored in javascript array
<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>
so here mysql code fetch two row frm db (Englishphp) but in result i got only php .. i want both of this row in javascript array so how to do that?