Пожалуйста, помогите мне сделать простой api rest в php для извлечения данных из базы данных и отображения в реагируйте js
У меня есть 3 столбца, имя, отдел и отметки.вот мой код php -
<?php
header("Content-Type: application/json; charset=UTF-8");
$con = mysqli_connect("mysql1004.mochahost.com","a310387_task_for","task_force","a310387_task_force");
$query=mysqli_query($con,'select * from student');
$json_array=array();
while($rows=mysqli_fetch_assoc($query)){
$json_array[]=$rows;
}
echo json_encode($json_array);
?>
, а вот мой код реакции -
componentDidMount(){
fetch('http://veomit.com/test/zend/api/fetch.php')
.then(response => {
return response.json();
})
.then(result => {
this.setState({
UserData:result
});
});
}
с отображением вроде -
<tbody>
<tr>
{
this.state.UserData.map(function(item, key) {
return (
<tr key = {key}>
<td>{item.name}</td>
<td>{item.department}</td>
<td>{item.marks}</td>
</tr>
)
})
}
</tr>
</tbody>
, пожалуйста, помогите мне исправить это.заранее спасибо.