I created an array of values from data in MySQL. I then try to print it in Javascript but unfortunately it is not showing up.
Database has two cols: gurtej
and singh
<?php
require_once('config.php');
function readAttribute($connect){
$resultArray=array();
$sql="SELECT Attributename,Entityname FROM temp_data_attribute";
$res=mysqli_query($connect,$sql);
echo mysqli_num_rows($res);
if(mysqli_num_rows($res)==0){
return 0;
}
else{
while($result=mysqli_fetch_array($res)){
array_push($resultArray,$result[0]);
}
return $resultArray;
}
}
?>
<html>
<body>
<script>
var jArray= <?php
$resultArray=readAttribute($connect);
if($resultArray==0){
$resultArray=[];
}
echo json_encode($resultArray);?>;
var counter=<?php echo count($resultArray);?>;
document.write(jArray[0]);
</script>
<?php
print_r($resultArray);
?>
</body>
</html>
And when i try to print it in php using print_r
this is the result.
Array ( [0] => gurtej [1] => singh )